Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
452 views
in Technique[技术] by (71.8m points)

c# - Is there a resharper comment directive to disable code cleanup for a class?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 StructLayoutAttribute:

 <!--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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...