How to disable specific Code Analysis Warning for entire class
<p>I'm trying to disable a code analysis rule across an entire class, but NOT for the entire project, just a single class.  In the example below, the build generates a CA1822 warning because it thinks that the unit test methods should be static.</p>

<p>The fix is to add the following attribute to each unit test method:
<code>[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]</code></p>

<p>However, that's cumbersome and clutters a class with many unit tests.</p>

<p>I've tried:</p>

<ol>
<li>Moving the attribute to the class</li>
<li>Wrapping all of the methods in </li>
</ol>

<p><code>#pragma warning disable CA1822</code></p>

<p><code>#pragma warning restore CA1822</code></p>

<p>Neither of these two approaches have worked.</p>

<pre><code>public class TestClass
{
    public TestClass()
    {
        // some setup here
    }

    [Fact]
    public void My_Unit_Test1()
    {
        // the 'this' parameter is never used, causes CA warning 1822
    }

    [Fact]
    public void My_Unit_Test2()
    {
        // the 'this' parameter is never used, causes CA warning 1822
    }
}
</code></pre>

<p>Using VS2015 Update 2, .net 4.61, and the new Code Analysis Analyzers.</p>