tags:

views:

45

answers:

2

I have a class where FileHelpers is dependent on the field order in this class file. If the class file ever gets a code clean up run against it that will cause the fields to be sorted alphabetically and invisibly ruin my class.

Since I would like to avoid this from ever accidentally occuring, is there a resharper comment directive to disable code cleanup for a class?

+1  A: 

I believe Resharper observes the [StructLayout(LayoutKind.Sequential)] attribute.

Will Dean
+2  A: 

You can customize the default member layout XML file and specify a pattern you want to ignore during the "reorder members" step of a code cleanup.

Have a look at the Type Member Layout section under the Resharper settings. You can see that there already are two exceptions defined for COM interfaces and Structs with the StuctLayoutAttribute:

 <!--Do not reorder COM interfaces-->
  <Pattern>
    <Match>
      <And Weight="100">
        <Kind Is="interface"/>
        <HasAttribute CLRName="System.Runtime.InteropServices.InterfaceTypeAttribute"/>
      </And>
    </Match>
  </Pattern>

<!--Do not reorder when StructLayoutAttribute is set -->
  <Pattern>
    <Match>
      <And Weight="100">
     <Or>
        <Kind Is="struct"/>
        <Kind Is="class"/>
     </Or>
        <HasAttribute CLRName="System.Runtime.InteropServices.StructLayoutAttribute"/>
      </And>
    </Match>
  </Pattern>

You could easily create your own IgnoreTypeMemberReorderingAttribute and add a small section in the XML file that check against it.

Romain Verdier