是否有ReSharper的评论指令禁用代码清理一类

是否有ReSharper的评论指令禁用代码清理一类

本文介绍了是否有ReSharper的评论指令禁用代码清理一类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类,其中FileHelpers是依赖在这个类文件中的字段顺序。如果类文件曾经得到一个代码清理对其运行,这将导致字段按照字母顺序排序,无形中毁了我的课。

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.

因为我想避免这种情况从曾经不小心存在的,是有ReSharper的评论指令禁用代码清理一类?

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

推荐答案

您可以自定义默认成员布局XML文件,并指定你想要的重新排序成员代码清理步骤过程中忽略的模式。

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.

有一个看的类型的成员布局的下ReSharper的设置部分。你可以看到,目前已经有对COM接口和对于结构定义了两个例外 StructLayoutAttribute

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>

您可以轻松创建自己的 IgnoreTypeMemberReorderingAttribute 和补充说,对证XML文件中的一小部分。

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

这篇关于是否有ReSharper的评论指令禁用代码清理一类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 18:43