tags:

views:

35

answers:

1

So this is a follow-up to Keith Nicholas' question from 2 years ago:

Formatting Resharper backing fields for properties in C#

My guess is this would probably involve a custom Type Members Layout. Is there a way to to this yet in the latest Resharper version (as of now, it's 5.1) yet?

A: 

Sure, at least with Resharper 5.1.1727 you can add an entry like the following

<!--fields-->
<Entry>
  <Match>
      <Kind Is="field"/>
  </Match>
  <Sort>
    <Static/>
    <Readonly/>
    <Name/>
  </Sort>
</Entry>

to the Type Members Layout to indicate where you want the backing fields to appear in the class.

For example, if you want fields at the bottom of the class insert that section as the very last entry in the Default Pattern section:

  <!--Default pattern-->
  <Pattern>

Resharper 5.1 comes with a default entry that includes fields:

<!--fields and constants-->
<Entry>
  <Match>
    <Or>
      <Kind Is="constant"/>
      <Kind Is="field"/>
      <Kind Is="event"/>
    </Or>
  </Match>
  <Sort>
    <Kind Order="constant field"/>
    <Static/>
    <Readonly/>
    <Name/>
  </Sort>
</Entry>

so that it will not conflict with your new rule, remove field from the default entry e.g.

<!--events and constants-->
<Entry>
  <Match>
    <Or>
      <Kind Is="constant"/>
      <Kind Is="event"/>
    </Or>
  </Match>
  <Sort>
    <Kind Order="constant event"/>
    <Static/>
    <Readonly/>
    <Name/>
  </Sort>
</Entry>
Handcraftsman
Yes, I do this currently (placing all fields together), but I'd like to have each backing field immediately above the property that it is associated with.
David McClelland