可以禁用Visual Studio的代码分析检查编译器生成的代码吗?

时间:2014-04-29 16:45:28

标签: c# code-analysis stylecop

在我的代码库中,我有一堆看起来像这样的测试代码:

// define proxy that I can assign my own delegate to
protected delegate void VerifyStop();
protected VerifyStop StopProxy { get; set; }

// in the test code assign a delegate appropriate for what I'm testing...
this.StopProxy = () =>
{
    notificationWasSent = true;
    Assert.AreEqual(....);
};

// call framework code that will eventually call my StopProxy code.

我正在测试的框架调用StopProxy方法,这让我设置一个lambda来验证框架行为。

当我运行Visual Studio代码分析时,我会收到有关编译器从我给它的lambda写入的代码中未使用的私有字段的警告。

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Scope = "member", Target = "AutoTraderTest.PairOpenClose1ATest+<>c__DisplayClass12.#CS$<>8__localsd")]

目前我只是在测试项目的GlobalSuppression.cs文件中单独忽略它们,但是如果每个测试可以有5个lambda并且我可以有100个测试,这会导致许多故意禁用的警告。这也使得GlobalSuppression.cs文件难以解析。

我喜欢我生成的代码警告,但对于自动生成的代码有没有办法关闭此错误而不必忽略每个实例?

我看过这个问题:

How to configure StyleCop to suppress warnings on generated code?

但是它讨论了禁用对整个文件的检查,而不是编译器生成的代码,这是我不想要的。

0 个答案:

没有答案
相关问题