Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否可以禁用Visual Studio对编译器生成的代码的代码分析检查?_C#_Code Analysis_Stylecop - Fatal编程技术网

C# 是否可以禁用Visual Studio对编译器生成的代码的代码分析检查?

C# 是否可以禁用Visual Studio对编译器生成的代码的代码分析检查?,c#,code-analysis,stylecop,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 =

在我的代码库中,我有一堆测试代码,如下所示:

// 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来验证框架行为

当我运行VisualStudio代码分析时,我从编译器从我提供的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文件难以解析

我喜欢我生成的代码的警告,但是对于自动生成的代码,有没有一种方法可以在不忽略每个实例的情况下关闭此错误

我已经看了这个问题:


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

在测试项目中使用代码分析让我觉得非常低效。在最后一个项目中使用它,也就是真正使用这个类的项目。@Hans,我同意你的看法。然而,出于这个问题的目的,我们可以假设这个生产代码还是我在这件事上没有选择余地?这毫无意义。如果生产代码产生了这些警告,那么您不应该忽略它们。@Hans,那么可能是我不理解,但是如果我创建了上面使用的lambda,我仍然会收到关于未使用代码的代码分析警告。未使用的代码是由编译器生成的。@HansPassant:正确性、可读性和可维护性验证对于测试代码和生产代码来说可能同样重要,或者至少同样重要。我非常不同意,当人们重视测试代码的质量时,对测试代码运行静态分析会适得其反。诚然,测试代码在每个项目或产品上的价值并不相等,但当它是。。。