How to suppress code analysis messages for all type members?

删除回忆录丶 提交于 2019-11-27 23:38:28

There is no way to suppress a rule for a whole class or enum in this case and have the suppression apply to all of its members, unfortunately.

But what you can do, is create a CodeAnalaysisDictionary.xml, add it to your project containing the Enum and setting its 'Build action' propery to CodeAnalysisDictionary:

Once you have set this up, you can add the abbreviations and case exceptions to the dictionary like this:

<Dictionary>
      <Acronyms>
         <CasingExceptions>
            <Acronym>AED</Acronym>
            <Acronym>AFN</Acronym>
            <Acronym>ALL</Acronym>
            <Acronym>...</Acronym>
         </CasingExceptions>
      </Acronyms>
</Dictionary>

While these exceptions will apply to any element in the code with these acronyms in them, they will prevent the CA1709 warnings from showing up.

See the documentation for more information on the exceptions you can setup using the dictionary files:

Nicole Calinoiu

No, there is no way to do this without individual suppressions. The Scope argument lets the code analysis engine know what kind of thing the Target argument represents. For example, if the 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" would perhaps have been better represented by a name like "TargetKind", but that, unfortunately, does not change what it actually represents.

Given the ugliness of the suppressions in this case, you might want to generate them into GlobalSuppressions.cs, then move them into a separate file like CurrencyTypeMemberNameSuppressions.cs, which you could (optionally) nest as a file under the file containing your CurrencyType enum in your project structure in Visual Studio. Not ideal, but maybe the best choice of a bad lot at this point...

Also see this answer.

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