In ReSharper 3.0 you now have the ability to specify how the Reformat action (Shortcut: Ctrl+Alt+F) should order the members within your code file.
The re-ordering feature is very nice if you want to adhere to a coding standard. e.g. Castle Project Coding Standards. Below is a breakdown of how ReSharper 3.0 would structure your code if you use the Re-order settings file:
- Every section is sorted by Access i.e. public, protected, internal, private
- Sections from top to bottom:
- Delegates
- Enums
- Constants
- Static & Readonly Fields
- Fields
- Constructors (Static then Instance)
- Destructors
- Instance Indexers (Sorted by Abstract, Virtual, Override)
- Instance Properties (Sorted by Abstract, Virtual, Override)
- Instance Methods (Sorted by Abstract, Virtual, Override)
- Event Handling Methods
- Events Declarations
- Operators
- Interface Implementations
- Class Indexers (Sorted by Abstract, Virtual, Override)
- Class Properties (Sorted by Abstract, Virtual, Override)
- Class Methods (Sorted by Abstract, Virtual, Override)
- All other members
- Nested Types
I thought the ReSharper 3.0 & Castle community might find the re-order settings file I created helpful.
To add the settings you should open the Type Member Layout section of the ReSharper 3.0 beta options screen:
And then Copy the following XML into the Custom Patterns box:
<?xml version="1.0" encoding="utf-8" ?>
<Patterns xmlns="urn:shemas-jetbrains-com:member-reordering-patterns">
<!--Do not reorder COM interfaces-->
<Pattern>
<Match>
<And Weight="100">
<Kind Is="interface"/>
<HasAttribute CLRName="System.Runtime.InteropServices.InterfaceTypeAttribute"/>
</And>
</Match>
</Pattern>
<!--Special formatting of NUnit test fixture-->
<Pattern RemoveAllRegions="true">
<Match>
<And Weight="100">
<Kind Is="class"/>
<HasAttribute CLRName="NUnit.Framework.TestFixtureAttribute" Inherit="true"/>
</And>
</Match>
<!--Setup/Teardow-->
<Entry>
<Match>
<And>
<Kind Is="method"/>
<Or>
<HasAttribute CLRName="NUnit.Framework.SetUpAttribute" Inherit="true"/>
<HasAttribute CLRName="NUnit.Framework.TearDownAttribute" Inherit="true"/>
<HasAttribute CLRName="NUnit.Framework.FixtureSetUpAttribute" Inherit="true"/>
<HasAttribute CLRName="NUnit.Framework.FixtureTearDownAttribute" Inherit="true"/>
</Or>
</And>
</Match>
<Group Region="Setup/Teardown"/>
</Entry>
<!--All other members-->
<Entry/>
<!--Test methods-->
<Entry>
<Match>
<And Weight="100">
<Kind Is="method"/>
<HasAttribute CLRName="NUnit.Framework.TestAttribute" Inherit="false"/>
</And>
</Match>
<Sort>
<Name/>
</Sort>
</Entry>
</Pattern>
<!--Default pattern-->
<Pattern RemoveAllRegions="true">
<!--delegate-->
<Entry>
<Match>
<And Weight="100">
<Access Is="public"/>
<Kind Is="delegate"/>
</And>
</Match>
<Sort>
<Access Order="public protected internal private" />
<Name/>
</Sort>
<Group Region="Delegates"/>
</Entry>
<!--enums-->
<Entry>
<Match>
<Kind Is="enum"/>
</Match>
<Sort>
<Access Order="public protected internal private" />
<Name/>
</Sort>
<Group Region="Enums"/>
</Entry>
<!--constants-->
<Entry>
<Match>
<Kind Is="constant"/>
</Match>
<Sort>
<Access Order="public protected internal private" />
<Name/>
</Sort>
<Group Region="Constants"/>
</Entry>
<!--static and readonly fields-->
<Entry>
<Match>
<And>
<Kind Is="field"/>
<Or>
<Static/>
<Readonly/>
</Or>
</And>
</Match>
<Sort>
<Access Order="public protected internal private" />
<Name/>
</Sort>
<Group Region="Readonly & Static Fields"/>
</Entry>
<!--fields-->
<Entry>
<Match>
<Kind Is="field"/>
</Match>
<Sort>
<Access Order="public protected internal private" />
<Name/>
</Sort>
<Group Region="Fields"/>
</Entry>
<!--Constructors. Place static one first-->
<Entry>
<Match>
<Kind Is="constructor"/>
</Match>
<Sort>
<Static/>
<Access Order="public protected internal private" />
</Sort>
<Group Region="C'tors"/>
</Entry>
<!--Destructors. Place static one first-->
<Entry>
<Match>
<Kind Is="destructor"/>
</Match>
<Sort>
<Static/>
<Access Order="public protected internal private" />
</Sort>
<Group Region="Destructors"/>
</Entry>
<!--Instance indexers-->
<Entry>
<Match>
<And>
<Kind Is="indexer"/>
<Not>
<Static/>
</Not>
</And>
</Match>
<Sort>
<Access Order="public protected internal private" />
<Abstract/>
<Virtual/>
<Override/>
<Name/>
</Sort>
<Group Region="Instance Indexers"/>
</Entry>
<!--instance properties-->
<Entry>
<Match>
<And>
<Kind Is="property"/>
<Not>
<Static/>
</Not>
<Not>
<Kind Is="indexer"/>
</Not>
</And>
</Match>
<Sort>
<Access Order="public protected internal private" />
<Abstract/>
<Virtual/>
<Override/>
<Name/>
</Sort>
<Group Region="Instance Properties"/>
</Entry>
<!--Methods-->
<Entry>
<Match>
<And>
<Kind Is="method"/>
<Not>
<Static/>
</Not>
<Not>
<HandlesEvent />
</Not>
<Not>
<Kind Is="destructor"/>
</Not>
</And>
</Match>
<Sort>
<Access Order="public protected internal private" />
<Abstract/>
<Virtual/>
<Override/>
<Name/>
</Sort>
<Group Region="Instance Methods"/>
</Entry>
<!--Event Handling-->
<Entry>
<Match>
<HandlesEvent />
</Match>
<Sort>
<Access Order="public protected internal private" />
<Abstract/>
<Virtual/>
<Override/>
<Name/>
</Sort>
<Group Region="Event Handling"/>
</Entry>
<!-- event -->
<Entry>
<Match>
<Kind Is="event"/>
</Match>
<Sort>
<Access Order="public protected internal private" />
<Name/>
</Sort>
<Group Region="Event Declarations"/>
</Entry>
<!-- operator -->
<Entry>
<Match>
<Kind Is="operator"/>
</Match>
<Sort>
<Access Order="public protected internal private" />
<Name/>
</Sort>
<Group Region="Operators"/>
</Entry>
<!--interface implementations-->
<Entry>
<Match>
<And Weight="100">
<Kind Is="member"/>
<ImplementsInterface/>
</And>
</Match>
<Sort>
<ImplementsInterface Immediate="true"/>
</Sort>
<Group>
<ImplementsInterface Immediate="true" Region="${ImplementsInterface} Members"/>
</Group>
</Entry>
<!--Class indexers-->
<Entry>
<Match>
<And>
<Kind Is="indexer"/>
<Static/>
</And>
</Match>
<Sort>
<Access Order="public protected internal private" />
<Abstract/>
<Virtual/>
<Override/>
<Name/>
</Sort>
<Group Region="Class Indexers"/>
</Entry>
<!--Class properties-->
<Entry>
<Match>
<And>
<Kind Is="property"/>
<Static/>
</And>
</Match>
<Sort>
<Access Order="public protected internal private" />
<Abstract/>
<Virtual/>
<Override/>
<Name/>
</Sort>
<Group Region="Class Properties"/>
</Entry>
<!--Class Methods-->
<Entry>
<Match>
<And>
<Kind Is="method"/>
<Static/>
</And>
</Match>
<Sort>
<Access Order="public protected internal private" />
<Abstract/>
<Virtual/>
<Override/>
<Name/>
</Sort>
<Group Region="Class Methods"/>
</Entry>
<!--all other members-->
<Entry/>
<!--nested types-->
<Entry>
<Match>
<Kind Is="type"/>
</Match>
<Sort>
<Name/>
</Sort>
<Group>
<Name Region="Nested type: ${Name}"/>
</Group>
</Entry>
</Pattern>
</Patterns>
Enjoy!





