I have a class like this one:
public class Foo
{
public readonly int A = 1;
public readonly int B = 2;
}
When I run VS2010 built in Code Analysis tool, I get 2 identical warnings: that 'field '...' is visible outside of its declaring type, change its accessibility to private and add a property, with the same accessibility as the field has currently, to provide access to it'.
I want to suppress this warning for all fields in my class Foo, but I don't want to mark every field with SuppressMessage attribute like this:
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 class members, using code like this:
[SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
public class Foo
{
public readonly int A = 1;
public readonly int B = 2;
}
But this code doesn't work, I still get a code analysis warning. How can I do it correctly?