获取FxCop禁止显示整个类型的警告? [英] Get FxCop to suppress warnings for a whole type?
问题描述
如何抑制整个类型的FxCop警告?
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")]
推荐答案
不幸的是,这不起作用。 FxCop仅处理针对与检测到的违规相同的目标声明的抑制。如果它在您的 Serialize
方法上发现违规,唯一会隐藏该违规的 SuppressMessage
属性要么是一个在方法本身上声明,或使用其 Target
属性标识该方法的声明。
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 Serialize
method, the only SuppressMessage
attributes that will "hide" that violation are either one declared on the method itself or one whose Target
property identifies the method.
如果要禁止违反CA1000对于 Serializer< T>
类中的每个静态方法,都需要通过创建 SuppressMessage
来实现。
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 a SuppressMessage
attribute for each of those methods.
@Matt Faus :那么
Scope
参数的意义是什么?
@Matt Faus: What's the point of the
Scope
argument then?
Scope
参数使FxCop知道 Target
参数代表的是哪种东西。例如,如果 Target
是 ABC
,是否引用了名为 ABC的命名空间
还是命名空间 AB
中名为 C
的类? Scope
应该被命名为 TargetKind
之类的东西,但是不幸的是,这并没有改变它的实际含义……
The Scope
argument lets FxCop know what kind of thing the Target
argument represents. For example, if Target
is "A.B.C"
, does that refer to a namespace named A.B.C
or a class named C
in the namespace A.B
? Scope
should probably be named something like TargetKind
, but that, unfortunately, does not change what it actually represents...
另请参见此答案。
这篇关于获取FxCop禁止显示整个类型的警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!