如何抑制 StyleCop 警告“SA1201:所有方法必须放在所有属性之后。”?
可能的重复:
如何抑制 StyleCop 警告?
我正在编写一组方法,这些方法是私有/公共的混合体,需要放入同一区域(使用#region)。我使用了此处中提到的方法,但我无法抑制此警告。请帮忙。
[编辑] 我只需要抑制这个特定的警告 - 而不是整个项目/解决方案。不过我很想知道怎么做^_^
Possible Duplicate:
How to suppress a StyleCop warning?
I'm writing a group of methods which are a mix of private/public and need to put into the same region (using #region). I used method mentioned in here but I can not get this warning supressed. Please help.
[Edit]
I need to supress this particular warning only - not for the whole project/solution. But I'm willing to know how to do that ^_^
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
抑制 stylecop 警告的另一种方法是更好地使用它们。有一条规则坚持您不使用区域(默认情况下禁用)。如果不这样做,你的问题就会消失。
不使用区域,而是使用部分类。将您的区域提取到一个新的部分类中。
通过这种方式,您可以获得 stylecop 合规性和代码功能分离。两全其美。
An alternative to suppressing stylecop warnings is to use them better. There is a rule that will insist that you do not use regions (disabled by default). By not doing so, your issue goes away.
Instead of using regions, use partial classes. Extract your region into a new partial class.
In this way you get stylecop compliance and code functional separation. The best of both worlds.
在您的情况下,正确的
SuppressMessage
属性应如下所示:请注意,您可以将其放置在任何其他元素上(例如,放置在类上 - 那么整个类中的所有类似违规行为都将被抑制)。
我也同意在这些领域写什么是相当不明显的。
实际上,第一个应该是StyleCop分析器类的完全限定名称,可以从源代码中找到(例如来自此处)。
第二个应该以规则代码开头,然后是冒号和规则枚举的名称(幸运的是,它总是看起来像设置编辑器中显示的规则名称,但带有没有空格)。
In your case, correct
SuppressMessage
attribute should like like the following:Note that you can place it on any other element (e.g, on the class - then all similar violations in the entire class will be supressed).
I also agree that it's quite unobvious what to write in these fields.
Actually, the first one should be the fully qualified name of StyleCop analyser class and could be found from the source code (e.g. from here).
The second one should start with rule code, then colon and the name of the rule enumeration (luckily, it always looks like the rule name displayed in the Settings Editor, but with no whitespaces).
您愿意禁用整个项目的规则吗?如果是这样,请查看这是否适合您: 启用或禁用 StyleCop 规则
Are you happy to disable the rule for the whole project? If so, see if this works for you: Enabling or Disabling StyleCop Rules