如何抑制代码分析的消息对所有类型的成员? [英] How to suppress code analysis messages for all type members?

查看:320
本文介绍了如何抑制代码分析的消息对所有类型的成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有所有的货币的枚举:

Let's say I have an enumeration of all currencies:

public enum CurrencyType
{
    /// <summary>
    /// United Arab Emirates dirham
    /// </summary>
    [EnumMember]
    AED = 784,

    /// <summary>
    /// Afghan afghani
    /// </summary>
    [EnumMember]
    AFN = 971,

    /// <summary>
    /// Albanian lek
    /// </summary>
    [EnumMember]
    ALL = 008,

    ...
}

2015年VS代码分析不停抱怨100违反 CA1709 为每一位个体成员

VS 2015 code analysis keeps complaining about 100 violations of CA1709 for every individual member.

这是由本身就是一个有用的规则,我不想禁用它;但它是在这种特殊情况下没有太大的帮助,因为 CurrencyType 是公众和一大堆其他项目使用。

This is an useful rule by itself, and I do not want to disable it; yet it is of not much help in this specific case, as CurrencyType is public and is used in a whole lot of other projects.

我可以抑制消息;然而,仅VS提供我压制它为每一位个体成员 - 这意味着我将有100 [SuppressMessage(...)] 线,这将杂乱的代码。

I can suppress the message; however, VS only offers me to suppress it for every individual member - meaning that I'll have 100 [SuppressMessage(...)] lines, which will clutter the code.

有什么办法来抑制所有CA1709所有 CurrencyType 成员,而不是抑制它在所有其他代码这个项目,而无需编写100 [SuppressMessage(...)]

Is there any way to suppress all CA1709 for all CurrencyType members, while not suppressing it for all other code in this project, without having to write 100 [SuppressMessage(...)]?

有一个 SuppressMessageAttribute 参数>,但文档是一个不清楚。我试图把两者

There is a Scope parameter of SuppressMessageAttribute, but the documentation is unclear on that one. I've tried placing both

[SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", Scope = "type", Justification = "Currency codes are defined in ISO standard.")]

[SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", Scope = "member", Justification = "Currency codes are defined in ISO standard.")]

CurrencyType 本身。无论是做的工作。

on CurrencyType itself. Neither does work.

推荐答案

有没有办法制止在这种情况下,全班或枚举的规则,并有抑制适用于所有成员,很可惜。

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.

但你可以做什么,是创建一个 CodeAnalaysisDictionary.xml ,它添加到包含枚举和建设行动属性格式设置为 CodeAnalysisDictionary 项目:

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>



虽然这些例外情况将适用于在他们这些缩写代码的任何元素,它们会阻止。CA1709警告,从显示出来。

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:

  • https://msdn.microsoft.com/en-us/library/bb514188.aspx#bkmk_dictionaryacronymscasingexceptionsacronym

这篇关于如何抑制代码分析的消息对所有类型的成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆