How to supress StyleCop warning “SA1201: All methods must be placed after all properties.”? [duplicate]

£可爱£侵袭症+ 提交于 2020-01-04 06:54:45

问题


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 ^_^


回答1:


Are you happy to disable the rule for the whole project? If so, see if this works for you: Enabling or Disabling StyleCop Rules




回答2:


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.




回答3:


In your case, correct SuppressMessage attribute should like like the following:

[SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1202:ElementsMustBeOrderedByAccess")]
private void SomeMethod()
{
}

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



来源:https://stackoverflow.com/questions/3287957/how-to-supress-stylecop-warning-sa1201-all-methods-must-be-placed-after-all-pr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!