Disable all Resharper warnings with a comment

倾然丶 夕夏残阳落幕 提交于 2019-11-29 01:02:54

According to this blog post on the JetBrains blog, in ReSharper 8 there will be a single comment that can disable resharper in a file.

It will be

// ReSharper disable All

Note: The "All" is case-sensitive, the rest is not.

Nial, you can press Ctrl + Shift + Alt + 8 to disable analyses and highligtings in current file.

The following worked for me.

  • Add "No Resharper" to Generated Code Regions in R# -> Options -> Code Inspection -> Generated Code
  • Use the following to suppress the warnings:

    #region No Resharper
    
    // All R# warnings are suppressed here
    
    #endregion
    

You could also use the SuppressMessageAttribute with ReSharper as the category and All as the checkId on the method or the class as shown below. This is more granular than disabling everything in the file if you need the fine grained control.

Tested with Visual Studio 2015 Update 3 and ReSharper Ultimate 10.0.2

[SuppressMessage("ReSharper", "All")]
private void MethodWithMultipleIssues()
{
    TestClass instance = null;
    // You would get an "Expression is always true" message
    if (instance == null)
    {
        Debug.WriteLine("Handle null");
    }
    else
    {
        // You would get an "Code is unreachable" message
        Debug.WriteLine("Handle instance");
    }
}
Sven Hackober

You can add the file to the list of "Generated Code" in ReSharpers Options Menu:

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