忽略Visual Studio中的代码分析规则

Ale*_*gas 6 code-analysis visual-studio-2008 visual-studio

如何在以下内容中忽略特定的VS代码分析规则(例如CA1305:Microsoft.Globalization):

  • 方法?
  • 类?
  • 命名空间?

(假设这些选项都是可能的.)

Ant*_*nes 5

您可以像这样使用SupressMessage属性: -

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2233:OperationsShouldNotOverflow", MessageId = "newValue+1", Justification = "The reason I think its acceptable in this case")]
void SomeMethod()
{
   // Some code that would normal cause this Code Analysis message
}
Run Code Online (Sandbox Code Playgroud)

关于方法,属性,类型等


Ale*_*gas 1

我按照 @TrueWill 对 @AnthonyWJones 答案的评论的建议下载了 FXCop。这给了我 SuppressMessage:

[SuppressMessage("Microsoft.Globalization",
    "CA1305:SpecifyIFormatProvider",
    MessageId = "System.String.Format(System.String,System.Object)")]
Run Code Online (Sandbox Code Playgroud)

这比原本应该的要困难得多。FXCop 集成到 Visual Studio 中发生了什么?感谢回答者的帮助。