VS2010 code analysis. Suppress message CA1051:DoNotDeclareVisibleInstanceFields for all class members

依然范特西╮ 提交于 2019-12-04 09:04:50

There is no way to suppress more than 1 message at a time using SuppressMessageAttribute.

As discussion can be found here, but the relevant part is:

You are running into a common misunderstanding about SuppressMessage.

Each time you put a SuppressMessage in a source file, you suppress exactly one problem (one "row" in the grid). Period.

A SuppressMessage may be placed either "near" the violation or at the module-level. Module-level, assembly-level, and global suppression all mean the same thing. By placing at the module-level, you do not suppress multiple instances of the problem at once. You merely get to locate the SuppressMessage in a different place of the code. The main benefit is that you can, for example, collect all the suppressions related to the assembly in a single file (for example, GlobalSuppressions.cs).

When you use a module-level SuppressMessage, you must specify the Target. The Target must match exactly what is reported in the GUI for a violation of the rule.

There is no way to use SuppressMessage to suppress a rule for the entire scope of a class or the entire scope of a namespace.

You can create the CodeAnalysis rules file with a set of rules like:

<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="New Rule Set" Description=" " ToolsVersion="10.0">
  <Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis"
         RuleNamespace="Microsoft.Rules.Managed">
    <Rule Id="CA1111" Action="Ignore" />
  </Rules>
</RuleSet>

See step by step walkthrough:

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