(目前)没有办法在 ReSharper 中开箱即用地执行此操作。幸运的是,ReSharper 拥有非常丰富的可扩展性 API(尽管文档很少)。我花了很多时间与 Reflector 一起尝试解决问题。
We use a similar alignment guideline for class members in a company I work for (to the extreme, we also align method parameters). I wrote a plugin for ReSharper to help me do just that. It's a "Code Cleanup" module, which runs sometime during the code cleanup (Ctrl-E, Ctrl-F) and aligns the code for you. It also makes the class sealed
, if possible.
一些例子:
方法参数:
public void DoSomething(string name,
int age,
IEnumerable coll)
(你需要改变包装形式参数 to 总是砍 in 选项->格式样式->换行和换行为了使其正常工作)
常数:
private const int RESOURCEDISPLAYTYPE_DOMAIN = 0x00000001;
private const int CONNECT_COMMANDLINE = 0x00000800;
private const int CONNECT_INTERACTIVE = 0x00000008;
private const string RESOURCE_NAME = "Unknown";
You can download the source code from my SkyDrive.
Edit I seem to have lost access to that SkyDrive, and lost the files too. This was before github :(
请注意,您需要一些东西来编译/调试它:
-
更新Command Line Arguments
in Debug
tab in Project
Properties
与正确的路径
输出DLL:
/ReSharper.Plugin
"X:\<projects>\MyCompany.CodeFormatter\MyCompany.CodeFormatter\bin\Debug\MyCompany.CodeFormatter.dll"
This allows debugging the plugin via
F5, and it will be
automatically installed in
ReSharper's Plugins in the new
Visual Studio instance which will
open.
- 该插件适用于 ReSharper 4.5,它引用了该版本的 DLL。如果您在其他地方安装了 ReSharper,除了
C:\Program Files\JetBrains\ReSharper
,您将必须修复参考。
- 这不会对齐方法内的变量,但添加应该不难:)
安装后,只需运行Code Cleanup
修复您的对齐方式(不幸的是,我从未收到 JetBrains 关于如何在大括号/分号格式化期间执行此操作的回复)。
大会被重命名是为了保护无辜者:)
祝你好运!