How can I suppress FxCop warnings for a whole type?
namespace ConsoleApplication1
{
public static class Serializer<T>
{
public static string Serialize(T obj)
{
return string.Empty;
}
public static T Deserialize(string str)
{
return default(T);
}
}
I tried this, but it is not working for me:
[assembly: SuppressMessage("Microsoft.Design",
"CA1000:DoNotDeclareStaticMembersOnGenericTypes", Scope = "Type",
Target = "ConsoleApplication1.Serializer'1")]
Unfortunately, this will not work. FxCop only processes suppressions that are declared against the same target as a detected violation. If it finds a violation on your
Serializemethod, the onlySuppressMessageattributes that will "hide" that violation are either one declared on the method itself or one whoseTargetproperty identifies the method.If you want to suppress a CA1000 violation for each of your static methods in the
Serializer<T>class, you will need to do this by creating aSuppressMessageattribute for each of those methods.The
Scopeargument lets FxCop know what kind of thing theTargetargument represents. For example, ifTargetis"A.B.C", does that refer to a namespace namedA.B.Cor a class namedCin the namespaceA.B?Scopeshould probably be named something likeTargetKind, but that, unfortunately, does not change what it actually represents...Also see this answer.