Tools – Code style tools – Resharper and StyleCop Options node
Topic: Tools – Code style tools – Resharper and StyleCop Options ide
標題: 工具 –代碼風格工具 – Resharper 和StyleCop 選項 工具
Stylecop 和 reshaper code style 插件能夠幫助組寫出優雅的,易懂的,立刻能夠轉化的一組指令,他的做用尤爲是在跨多個region的時候明顯。 this
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. spa
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. code
咱們使用的Stylecop的規則以下所示: orm
The stylecop rule that we use is as follow. ci
實際上,你能夠編輯這個規則,工具是「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.
若是單掃描一個文件,咱們能夠右鍵單擊文檔, 而後選擇Run stylecop」
To run stylecop on a single file, you can right click on the document, and then select 「Run stylecop」
或者你能夠掃描全部的文件,方法是「Tools | Run Stylecop (Rescan All)」
Or you can run through all files by 「Tools | Run Stylecop (Rescan All)」
你也能夠選擇幾個project,folder來掃描,以下所示
. You can run the Stylecop scan also by right clicking on the project/solution node.
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 | Options | Code Editing | Code Cleanup能夠打開「Code cleanup」頁面。
And from the Resharper | Options | Code Editing | Code Cleanup , you can open up the 「Code Cleanup」 option.
有一些格式化的命令是按照語言選項來的,好比,是否將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
Pic – C# Options on Braces layout (by changing Array and Object initialize from GNU style to BSD style).
關於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