sha*_*atl 11 .net c# code-analysis fxcop suppressmessage
如何抑制整个类型的FxCop警告?
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);
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试过这个,但它对我不起作用:
[assembly: SuppressMessage("Microsoft.Design",
"CA1000:DoNotDeclareStaticMembersOnGenericTypes", Scope = "Type",
Target = "ConsoleApplication1.Serializer'1")]
Run Code Online (Sandbox Code Playgroud)
Nic*_*oiu 10
不幸的是,这不起作用.FxCop仅处理针对检测到的违规而针对同一目标声明的抑制.如果它在您的Serialize方法中发现违规SuppressMessage,则"隐藏"该违规的唯一属性是在方法本身上声明的Target属性或其属性标识方法的属性.
如果要为类中的每个静态方法抑制CA1000违规Serializer<T>,则需要通过SuppressMessage为每个方法创建属性来执行此操作.
@Matt Faus:那么
Scope争论有什么意义呢?
该Scope参数让FxCop知道Target参数代表什么样的东西.例如,如果Target是"A.B.C",这是否指的是已命名空间A.B.C或命名类C的命名空间A.B?Scope可能应该被命名为TargetKind,但不幸的是,这并没有改变它实际代表的东西......
另见这个答案.