views:

272

answers:

2

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  A: 

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.

Steve Dunn
+1  A: 

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.

Sky Sanders
The "anonymous method body" option works (showing their slightly strange `DoSomethog()` method as an example), but R# still formats the other blocks with large indents.
adrianbanks
@adrianbanks - by unchecking "Indent array, object and collection initilizer blocks" my arrays and initializers are left alone. Not sure what DoSomethog() you are referring to though.
Sky Sanders
@adrianbanks - also, if your blocks are already pushed out from previous reformatting, r# is going to leave them alone. Set the first open brace where you want it, CTRL-D to format the rest, and subsequent code cleanup will not touch it.
Sky Sanders