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

半腔热情 提交于 2019-11-28 15:47:39
James Kolpack

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.

Resharper->Options->Languages->C#->File Layout

Select "All other members" and select "Sort by name" (highlighted in bottom right of pic)

In the XML file layout you have to add the element Entry.SortBy For example in All other members:

 <Entry DisplayName="All other members">
  <Entry.SortBy>
    <Name />
  </Entry.SortBy>
</Entry>

The problem with the 9.2 is that when the Entry.SortBy is missing from XML the selected value from the designer is not saved.

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