CA1704 - Microsoft seems to be blocking the word 'Multi'?

风格不统一 提交于 2019-12-10 01:47:57

问题


public class MultiSomething { } //CA1704:IdentifiersShouldBeSpelledCorrectly

When I run Code Analysis, I get an error because the Microsoft does not recognize the word 'Multi' (go figure they use it in IMultiValueConverter). So, what I did to correct this was to add a CodeAnalysisDictionary.xml file and followed the steps supplied here. However, it doesn't seem to solve the situation, I still get a Code Analysis warning message.

To ensure that this isn't a bug with the recognized words section, I added another class and another exception.

public class MultiSomething { } //CA1704:IdentifiersShouldBeSpelledCorrectly
public class MutiiSomething { } //NO WARNING

<Dictionary>
  <Words>
    <Recognized>
      <Word>Multi</Word> <-- This seems to not do anything... -->
      <Word>Mutii</Word> <-- This actually does something... -->
    </Recognized>
  </Words>
</Dictionary>

An alternative to fixing it is to use SuppressMessage, though that isn't a well fit solution if I plan on using this word all over the place.

[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Multi")]
public class MultiSomething { } //NO WARNING (Suppressed)

Did Microsoft actually block 'Multi' from being added to the recognized words?


回答1:


You can refer to this feedback ticket. This is apparently by design.

The behavior you are seeing is because Code Analysis ships with a pre-defined custom dictionary that always overrides any other custom dictionaries when there is a conflict. In this case “multi” is listed as an <unrecognized> word in the default FXCop dictionary.

To fix this issue, open the default dictionary %VS Install Directory%\Team Tools\Static Analysis Tools\FxCop\CustomDictionary.xml and comment out or remove the “multi” entry from the <unrecognized> words section; "multi" will no longer be flagged as a spelling error in Code Analysis.




回答2:


try adding this to your customdictionary

<Deprecated>
  <Term PreferredAlternate="Multi">multi</Term>
</Deprecated>



回答3:


You can add an XML File with Word Acronyms etc...

Add your xml file and set Build Action = CodeAnalysisDictionary

<?xml version="1.0" encoding="utf-8" ?>
<Dictionary>
  <Words>
    <Unrecognized>
      <Word></Word>
    </Unrecognized>
    <Recognized>
      <Word>Multi</Word>
    </Recognized>
    <Deprecated>
      <Term PreferredAlternate=""></Term>
    </Deprecated>
    <Compound>
      <Term CompoundAlternate=""></Term>
    </Compound>
    <DiscreteExceptions>
      <Term>PostDate</Term>
    </DiscreteExceptions>
  </Words>
  <Acronyms>
    <CasingExceptions>
      <Acronym></Acronym> 
    </CasingExceptions>
  </Acronyms>
</Dictionary>


来源:https://stackoverflow.com/questions/7854518/ca1704-microsoft-seems-to-be-blocking-the-word-multi

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