Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resharper Clean-up Code - how to affect sorting of methods?

Tags:

resharper

I've got a customized clean-up and it's almost 'there'.

However, R# appears to want to sort the member methods, but at least it does not appear to be alphabetically.

Is there a way to force that sorting?

like image 220
Anders Juul Avatar asked Oct 02 '09 12:10

Anders Juul


People also ask

How do you code cleanup?

Right-click on the project or solution name in Solution Explorer, select Analyze and Code Cleanup, and then select Run Code Cleanup.

What does code cleanup do in Intellij?

tip. You can also run code cleanup using the command-line utility. JetBrains Rider allows you to apply formatting and other code style preferences in a bulk mode to instantly eliminate code style violations in one or more files, in a project or in the entire solution.

What is code cleanup in Visual Studio 2019?

"Code Cleanup is a new feature of Visual Studio 2019 that will automatically clean up your code file to make sure it is formatted correctly and that your coding style preferences are applied," the marketplace description says.


1 Answers

Customizing the layout can indeed be accomplished with Resharper. Go to:

Resharper->Options->Languages->C#->Formatting Style->Type Members Layout

ReSharper 2017

Resharper -> Options-> Code Editing -> C# -> File Layout -> Interface Implementations/All Other Members

and uncheck the "Use Default Patterns" option.

Now you'll want to edit the xml in the "Custom Patterns" box. I'd recommend copying it out to an editor that can properly hi-light the xml (notepad++ or visual studio should work fine).

Now, find the section near the bottom:

    <!--all other members-->     <Entry/> 

and change it to:

    <!--all other members-->     <Entry>       <Match>         <Kind Is="method"/>       </Match>       <Sort>         <Name/>       </Sort>     </Entry> 

Now, make sure that your cleanup profile has "Reorder type members", and then right click on the filename in solution explorer and do "Cleanup code...". I've just tried this myself and it does order the methods alphabetically.

If you want to also sort by access type, you can add this under the <Sort> element:

<Access Order="public protected internal private" /> 

Here's an article to learn more.

like image 193
James Kolpack Avatar answered Sep 21 '22 17:09

James Kolpack