ReSharper Web Help

ReSharper reorders type members in C# code files according to the xml pattern.

To reorder type members
  1. Choose ReSharper | Options | Languages | C# | Type Members Layout.
  2. In the Type Members Layout tab you can clear Use Default Patterns check box and modify xml pattern according to your needs.
  3. Choose Tools | Code Cleanup in ReSharper Options dialog box.
  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 OK to save changed pattern and new profile, close the ReSharper Options dialog box.
  6. Open the Code Cleanup dialog box from the text editor or Solution Explorer as described in Running Code Cleanup .
  7. When the Code Cleanup dialog box opens, select the newly created profile in the Available Profiles area.
  8. Click Run to perform Code Cleanup. ReSharper will reorder type members according to your settings.

Modifying the Default Pattern

You can edit the default pattern to satisfy your needs. The xml file contains a number of patterns. Match-tag defines what kind of entities the pattern matches. Sort-tag specifies how entities should be sorted. Group-tag specifies how entities should be grouped and embraced with a region. Consider the example below:

Reordering Type Members

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. And-tag and or-tag perform logical-and and logical-or operations, respectively. Not-tag negates the value of an expression within a pattern.

Let’s move to the next example:

Reordering Type Members

This xml-code matches members, which implement an interface, surrounds them with regions and sorts by implemented interface name. The ${ImplementsInterface} variable contains the name of the interface being implemented. If you don’t want regions around interface implementations, remove the group-tag and ReSharper will just sort members according to the name of the interface they’re implementing.

Another example:

Reordering Type Members

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

See Also