问题描述
我喜欢我的格式化code对齐平等操作数的右侧。结果
喜欢这里:
I like to formatting my code to align right side of equal operands.
Like here:
bool canRead = false;
bool canReadClass = true;
string className = boType.Name;
最近,我已经切换到ReSharper的,并发现它非常有用,但找不到选项允许我格式code中所描述的方式。
I've switch to ReSharper recently and found it very useful but cannot find option allowing me format code in described way.
你知道,如果有这样的选项/插件吗?结果
也许你知道的比ReSharp解决方案等,允许吗?
Do you know if there is such option / plugin?
Maybe you know other than ReSharp solution allowing that?
编辑:结果
如何决定什么code的一部分,应对准?结果
我的约定,对准同一个街区的所有变量。结果
通过块我的意思是code部分没有空行分配。
How to decide what part of code shall be aligned?
My convention is aligning all variables in same block.
By "block" I meant part of code not divided by empty lines.
例如
// First block
int count = 10;
string name = "abc";
bool calculate = true;
.....
.....
// Second block
MyOwnType myType = new MyOwntype();
int count = 10;
修改-2 结果
我已经打开这一点。如果有人有兴趣的 !
EDIT -2
I've opened R# ticket for this. If anyone interested please vote!
推荐答案
有是(目前)没有办法做到这一点,在ReSharper的盒子。幸运的是,ReSharper的有一个非常丰富的可扩展API(虽然不良记录)。我花了很多时间与反射器试图理出头绪。
There is (currently) no way to do this out of the box in ReSharper. Fortunately, ReSharper has a very rich extensibility API (albeit poorly documented). I've spent a lot of time with Reflector trying to figure things out.
我们使用类成员类似的对齐准在我工作的公司(到了极致,我们也对齐方法参数)。我写了ReSharper的一个插件来帮助我做到这一点。这是一个code清理模块,其中code清理过程中运行一段时间(控制骨节病> - 电子骨节病>,控制骨节病> - ˚F骨节病>),并对齐code你。这也使得该类密封
,如果可能的话。
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 (-, -) and aligns the code for you. It also makes the class sealed
, if possible.
一些例子
的方法参数:的
public void DoSomething(string name,
int age,
IEnumerable coll)
(您将需要更改裹形式参数为印章总是选项 - >格式化风格 - >换行和包装这个正常工作)
(you will need to change Wrap formal parameters to Chop always in Options->Formatting Style->Line Breaks and Wrapping for this to work properly)
的的常量:的
private const int RESOURCEDISPLAYTYPE_DOMAIN = 0x00000001;
private const int CONNECT_COMMANDLINE = 0x00000800;
private const int CONNECT_INTERACTIVE = 0x00000008;
private const string RESOURCE_NAME = "Unknown";
结果
修改我似乎失去了访问该SkyDrive中,太丢失的文件。这是github上之前:(
Edit I seem to have lost access to that SkyDrive, and lost the files too. This was before github :(
请注意,您将需要几件事情要编译/调试吧:
Please note that you'll need several things to compile/debug it:
-
更新
命令行参数
在调试
在标签项目
与正确的路径
属性
输出DLL:
Update the
Command Line Arguments
inDebug
tab inProjectProperties
with the correct path ofthe output DLL:
/ReSharper.Plugin
<$c$c>\"X:\\<projects>\\MyCompany.$c$cFormatter\\MyCompany.$c$cFormatter\\bin\\Debug\\MyCompany.$c$cFormatter.dll\"$c$c>
这允许通过调试插件
,这将是
自动安装在
ReSharper的的插件在新
Visual Studio的实例,它会
打开。
This allows debugging the plugin via, and it will beautomatically installed inReSharper's Plugins in the newVisual Studio instance which willopen.
在安装此之后,只需运行 code清理
来修复您对齐(我从来没有从JetBrains公司有关如何括号中做到这一点的答复/分号格式化,可惜)。
After you install this, just run Code Cleanup
to fix your alignment (I never got a reply from JetBrains about how to do this during brace/semicolon formatting, unfortunately).
大会更名为保护无辜:)
Assembly was renamed to protect the innocent :)
祝你好运!
这篇关于ReSharper的格式:对齐平等操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!