如何正确地将首字母缩略词添加到 CustomDictionary.xml

How to properly add acronyms to CustomDictionary.xml

我的一个 类 有一个名为 Ttl 的 public 属性。这应该遵循 CA1709 规则:

By convention, two-letter acronyms use all uppercase letters, and acronyms of three or more characters use Pascal casing. The following examples use this naming convention: 'DB', 'CR', 'Cpa', and 'Ecma'. The following examples violate the convention: 'Io', 'XML', and 'DoD', and for nonparameter names, 'xp' and 'cpl'.

现在,代码分析抱怨我的 属性,告诉我它违反了 CA1704(拼写错误)。

我试过像这样将它添加到我的 CustomDictionary.xml 中:

<?xml version="1.0" encoding="utf-8" ?>
<Dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="CodeAnalysisDictionary.xsd">

  <!-- Some unimportant elements are here in the real file -->

  <Acronyms>
    <CasingExceptions>
      <Acronym>Ttl</Acronym>    <!--Time To Live-->
    </CasingExceptions>
  </Acronyms>

</Dictionary>

我尝试将小写、大写和驼峰式大小写放入字典,但其中 none 将消除拼写投诉。有没有办法将这个首字母缩略词添加到 XML 中,或者我是否只需要取消显示正确命名的 属性 的消息?

您添加了 "Ttl" 作为大小写例外。事实上不是。这是帕斯卡大小写的三个字母。

你没有做的是添加 "Ttl" 作为一个词。

<Words>
     <Recognized>
        <Word>Ttl</Word>

确保您确实需要它。大多数 .NET 语言都将 "no abbreviations" 作为良好的命名约定。