exceptionz

Thoughts on Technology, Methodology and Programming.

Resharper 3.0 Member Re-Ordering Settings

Posted by Marcus Wyatt on 10 June 2007

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.

image

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:

  1. Every section is sorted by Access i.e. public, protected, internal, private
  2. Sections from top to bottom:
    1. Delegates
    2. Enums
    3. Constants
    4. Static & Readonly Fields
    5. Fields
    6. Constructors (Static then Instance)
    7. Destructors
    8. Instance Indexers (Sorted by Abstract, Virtual, Override)
    9. Instance Properties (Sorted by Abstract, Virtual, Override)
    10. Instance Methods (Sorted by Abstract, Virtual, Override)
    11. Event Handling Methods
    12. Events Declarations
    13. Operators
    14. Interface Implementations
    15. Class Indexers (Sorted by Abstract, Virtual, Override)
    16. Class Properties (Sorted by Abstract, Virtual, Override)
    17. Class Methods (Sorted by Abstract, Virtual, Override)
    18. All other members
    19. 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:

image

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 &amp; 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!

del.icio.us Tags: , ,

About these ads

8 Responses to “Resharper 3.0 Member Re-Ordering Settings”

  1. Great template.

    Quick Note, when copying the XML from the HMTL the xml comments aren’t formatted correcly.

    instand of

  2. Thanks, mate…

  3. dsum said

    Thanks!

  4. Chris Martin said

    Perfect!!!

    Thanks. ;)

  5. JS said

    Many thanks – just what I was looking for.
    Cheers JS

  6. Earnestine Sarlo said

    Woah! I am really enjoying the template/theme of this site. It is simple, yet effective. A lot of times it is difficult to get that is perfect balance between user friendliness and appearance. I must say you have done a great job with this. Additionally, the blog loads super quick for me on Internet explorer. Superb Blog!

  7. Raffaeu said

    Still working
    Thanks for sharing this!

  8. donde invertir…

    [...]Resharper 3.0 Member Re-Ordering Settings « exceptionz[...]…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: