Is there a way to mark up code to tell ReSharper not to format it?

[亡魂溺海] 提交于 2019-11-27 05:53:39

问题


I quite often use the ReSharper "Clean Up Code" command to format my code to our coding style before checking it into source control. This works well in general, but some bits of code are better formatted manually (eg. because of the indenting rules in ReSharper, things like chained linq methods or multi-line ternary operators have a strange indent that pushes them way to the right).

Is there any way to mark up parts of a file to tell ReSharper not to format that area? I'm hoping for some kind of markup similar to how ReSharper suppresses other warnings/features. If not, is there some way of changing a combination of settings to get ReSharper to format the indenting correctly?

EDIT:

I have found this post from the ReSharper forums that says that generated code sections (as defined in the ReSharper options page) are ignored in code cleanup. Having tried it though, it doesn't seem to get ignored.


回答1:


Resharper>Options>Languages>C#>Formatting Style>Other>

Uncheck "Indent anonymous method body" and "Indent array, object and collection initilizer blocks" and anything else that strikes your fancy.




回答2:


As a last resort, if you've got legacy code that you don't want to format but you want additions to the class to be nicely formatted, then make the class partial and put new code in the new file.




回答3:


Check out this question I asked that involves the same issue: Resharper formatting code into a single line

The answer I got there work really good for me.



来源:https://stackoverflow.com/questions/2176429/is-there-a-way-to-mark-up-code-to-tell-resharper-not-to-format-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!