ReSharper Web Help

ReSharper can reorder type members in C# code files according to the specified pattern.

To reorder type members
  1. Choose ReSharper | Options in the main menu.
  2. In the ReSharper | Options | Code Editing | C# | Type Members Layout, choose a default member layout with or without regions, or configure a custom layout by modifying the default XML pattern.
  3. Open the Code Cleanup options: ReSharper | Options | Code Editing | Code Cleanup.
  4. Create a new profile as described in Creating Custom Profiles. In the Selected profile settings section for the new profile select Reorder type members check box.
  5. Click Save to apply the modifications and let ReSharper choose the settings layer, or choose a particular settings layer in the Save To drop-down list. To learn more about saving ReSharper settings, see JetBrains .NET Tools Blog: Save or Save To in ReSharper Options.
  6. Choose ReSharper | Tools | Cleanup Code in the menu to open the Code Cleanup dialog box for the current file or for a solution node (see Running Code Cleanup for details), and then select the newly created profile in the Available Profiles area.
  7. Click Run to perform Code Cleanup. ReSharper will reorder type members in the current file of in the selected solution node and according to your settings.

Modifying the default pattern

You can edit the default pattern according to your needs. The XML pattern allows for a number of tags: the Match tag defines what kind of entities the pattern matches; the Sort tag specifies how entities should be sorted; the Group tag specifies how entities should be grouped and embraced with a region. Consider the example below:

Code_Cleanup__Usage_Scenarios__Reordering_Type_Members_01

This XML code matches constant fields or fields, sorts them in such way that first go constant fields, then static fields, read-only fields and other fields sorted by their name in ascending order. The And tag and the Or tag perform logical-and and logical-or operations, respectively; the Not tag negates the value of an expression within a pattern.

Let’s move to the next example:

Code_Cleanup__Usage_Scenarios__Reordering_Type_Members_02

This XML code matches members that implement an interface, surrounds them with regions and sorts by the name of the implemented interface. The ${ImplementsInterface} variable contains the name of the interface being implemented. If you do not want to insert regions around interface implementations, remove the Group tag and ReSharper will just sort members according to the name of the interface they are implementing.

Another example:

Code_Cleanup__Usage_Scenarios__Reordering_Type_Members_03

Pay attention, that protected internal access modifier is referenced as protected-internal.

The following two examples show how to group members in regions. Grouping type methods into a region:

Code_Cleanup__Usage_Scenarios__Reordering_Type_Members_04

... and grouping private fields into a region:

Code_Cleanup__Usage_Scenarios__Reordering_Type_Members_05

This feature is supported in the following languages/technologies:

C# VB.NET HTML ASPX Razor JavaScript TypeScript CSS XML XAML RESX Build Scripts
feature_available