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. Open Code Editing | C# | Type Members Layout page of ReSharper options.
  3. In this page, you can choose a default member layout with or without regions, or configure a custom layout by modifying the default XML pattern.
  4. Open Code Editing | Code Cleanup options page.
  5. 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.
  6. 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.
  7. 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.
  8. 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:

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:

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:

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

See Also



External Links