tags:

views:

185

answers:

1

Hi all,

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?

Thanks,

Anders, Denmark.

+3  A: 

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

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

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

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

Here's an article to learn more.

James Kolpack
Thank you James for a very fine answer. As it turned out, it did not work at first until I realialized that a special handling is applied for interface implementations - which is what I was trying to sort. In my case the described edit should take place under the comment <!--interface implementations-->.Your answer was exactly right, though, for the problem as I phrased it in my question.
Anders Juul

related questions