工具 –代码风格工具 – Resharper 和StyleCop 选项

Tools – Code style tools – Resharper and StyleCop Options

Topic: Tools – Code style tools – Resharper and StyleCop Options

标题: 工具 代码风格工具 – Resharper StyleCop 选项

Stylecop reshaper code style 插件可以帮助组写出优雅的,易懂的,马上可以转化的一组指令,他的作用尤其是在跨多个region的时候明显。

Stylecop and reshaper code style plugin can help you and the team to achieve elegant styled, concise easy to ready set off instructions, especially when working across locational centres.

Stylecop rule

Stylecop是一个基于规则的工具,帮助你检查代码的风格,如果你有resharper安装的话,你可以在resharper使用Stylecop的规则。

Stylecop with its rule based tool can help you to check on the styling, it is a rule based tool, while if you have resharper installed. You will be able to check the code with Stylecop rule with context assistant.

我们使用的Stylecop的规则如下所示:

The stylecop rule that we use is as follow.


实际上,你可以编辑这个规则,工具是“StylecopSettingsEditor.exe”,使用的命令是如下所示的。 (但是我希望有一个工具能够从一个范例模板中创建出一个规则来)。

Actually you can edit the Stylecop editing with “StylecopSettingsEditor.exe” the command to run is as follow.  (while I hope there is a tool that can help generate Settings.Stylecop from a reference source code example).

“StylecopSettingsEditor.exe Settings.Stylecop”.

使用了改命令,如下的对话框会显示出来

It will bring up a dialog as follow.

工具 –代码风格工具 – Resharper 和StyleCop 选项

如果单扫描一个文件,我们可以右键单击文档, 然后选择Run stylecop”

To run stylecop on a single file, you can right click on the document, and then select “Run stylecop”

工具 –代码风格工具 – Resharper 和StyleCop 选项

或者你可以扫描所有的文件,方法是“Tools | Run Stylecop (Rescan All)”

Or you can run through all files by “Tools | Run Stylecop (Rescan All)”

工具 –代码风格工具 – Resharper 和StyleCop 选项

你也可以选择几个project,folder来扫描,如下所示

. You can run the Stylecop scan also by right clicking on the project/solution node.

工具 –代码风格工具 – Resharper 和StyleCop 选项

You may unload some unrelated projects to increate localization on the scanning result.

Integration with Resharper

Stylcope安装以后,可以和Resharper一起工作。

Stylcope after installation, can work with Resharper.

点击Resharper | Options | Tools | Stylecop,得到 Stylecop的工具页面。

On Resharper | Options | Tools | Stylecop, you will bring up the Style tool option page.

工具 –代码风格工具 – Resharper 和StyleCop 选项

Resharper | Options | Code Editing | Code Cleanup可以打开“Code cleanup”页面。

And from the Resharper | Options | Code Editing | Code Cleanup , you can open up the “Code Cleanup” option.

工具 –代码风格工具 – Resharper 和StyleCop 选项

有一些格式化的命令是按照语言选项来的,比如,是否将namespace import加入到braces layout的最低域。

While some of the code clean up are performed according to the language options, for examples, whether the namespace imports is added to the deepest scope or braces layout.

 Pic – C# option on Namespace import

工具 –代码风格工具 – Resharper 和StyleCop 选项

Pic – C# Options on Braces layout (by changing Array and Object initialize from GNU style to BSD style).

工具 –代码风格工具 – Resharper 和StyleCop 选项

关于braces layout GNU风格和BSD风格。

A special note on GNU style vs. BSD style

This is GNU style

Event += (o, arg) =>

..{

….DoWork()

 ..}

 

And this is the BSD style

 

Event += (o, arg) =>

{

..DoWork()

}

 

我们使用的Resharper的设置如下所示。

Hereby I attached the following R# settings.


You can find the attached settings from the wenku repository.

Reference:

Code cleanup – tool to move all using statements inside namespace in all cs files in my solution

 

 

你可能感兴趣的:(tools)