Code Analysis VS2010. Suppress message CA1051: DoNotDeclareVisibleInstanceFields for all members of the class

I have a class like this:

public class Foo
{
    public readonly int A = 1;
    public readonly int B = 2;
}

When I launch VS2010, which is built into the code analysis tool, I get the same warning 2 : that the "field" ... "is visible outside of its type of announcement, changes its accessibility to the closed one and adds a property with the same availability as the field is currently time to provide access to it. "

I want to suppress this warning for all fields of my Foo class , but I do not want to mark each field with the SuppressMessage attribute as follows:

public class Foo
{
    [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
    public readonly int A = 1;
    [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
    public readonly int B = 2;
}

I want to mark all members of the class using the following code:

[SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
public class Foo
{
    public readonly int A = 1;
    public readonly int B = 2;
}

, . ?

+5
2

, SuppressMessageAttribute.

, :

SuppressMessage.

, SuppressMessage , ( "" ). .

A SuppressMessage "" , . , . , . SuppressMessage . , , , ​​ (, GlobalSuppressions.cs).

SuppressMessage Target. , .

SuppressMessage .

+10

CodeAnalysis , :

<?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>

. :

+1

All Articles