Get FxCop to suppress warnings for a whole type?

白昼怎懂夜的黑 提交于 2019-12-30 08:17:23

问题


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")]

回答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 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.

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: What's the point of the Scope argument then?

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

Also see this answer.



来源:https://stackoverflow.com/questions/3253849/get-fxcop-to-suppress-warnings-for-a-whole-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!