Is there a way to disable all Resharper warnings for a file or section of code with a single comment? I'm trying to create some coding exercises for interviewing potential candidates, and the Resharper warnings give away the problem I want the candidate to spot :P Suppressing the specific warning still makes it obvious what the problem is.
有没有一种方法可以禁用一个注释的文件或代码段的所有Resharper警告?我正在尝试创建一些面试潜在候选人的编码练习,Resharper warning给出了我想要求职者发现的问题:P隐藏特定的警告仍然使问题很明显。
I still want to have Resharper available during the interview, I just want the candidate to spot this problem without Resharper spoiling the fun.
我还是想让Resharper在面试的时候出现,我只是想让你的面试官发现这个问题而不让Resharper破坏你的乐趣。
edit: Sorry I'll try to be more clear about what I'm after. I don't want to permanently disable a particular Resharper warning, I just want it to not show in one particular file, because the point of the exercise is to see if the developer understands the reason for the warning.
编辑:不好意思,我要更清楚地说明我想要什么。我不想永久禁用特定的Resharper警告,我只想让它不显示在一个特定的文件中,因为这个练习的目的是看看开发人员是否理解这个警告的原因。
To give one example, there is a Resharper warning to use the .Any extension method instead of Count() > 0, which I want the developer to point out themselves. To disable that warning, you have to use a comment of:
要给出一个示例,需要使用. any扩展方法而不是Count() >,我希望开发人员自己指出这一点。要禁用该警告,您必须使用以下注释:
// ReSharper disable UseMethodAny.0
around the code. That kind of gives the game away a little.
在代码。这样的游戏会让游戏变得更少。
I was trying to find something like:
我试着找到这样的东西:
// ReSharper disable all
which I could place at the top of the class, so it won't give away what I want the developer to find. But I can't seem to find a way to do that. Using numbers for the Resharper warnings would be fine as well, but I don't think it works that way?
我可以把它放在类的顶端,这样它就不会泄露我想让开发者找到的东西。但我似乎找不到一种方法。使用Resharper警告的数字也会很好,但是我不认为它是这样的。
6 个解决方案
#1
35
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.
根据JetBrains博客上的这篇文章,在ReSharper 8中会有一个注释可以在文件中禁用ReSharper。
It will be
这将是
// ReSharper disable All
Note: The "All" is case-sensitive, the rest is not.
注意:“All”是区分大小写的,其余则不是。
#2
41
Nial, you can press Ctrl + Shift + Alt + 8 to disable analyses and highligtings in current file.
Nial,您可以按Ctrl + Shift + Alt + 8来禁用当前文件中的分析和增强。
#3
5
The following worked for me.
以下是我的工作。
- Add "No Resharper" to Generated Code Regions in R# -> Options -> Code Inspection -> Generated Code
- 在r# ->选项->代码检查->生成的代码中添加“无Resharper”
-
Use the following to suppress the warnings:
使用以下方法来抑制警告:
#region No Resharper // All R# warnings are suppressed here #endregion
#4
2
you have to configure the ReSharper Inspections
你必须配置锐化检查
http://www.jetbrains.com/resharper/webhelp/Code_Analysis__Configuring_Warnings.html
http://www.jetbrains.com/resharper/webhelp/Code_Analysis__Configuring_Warnings.html
#5
2
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.
您还可以使用ReSharper作为类别和所有作为该方法或类的checkId(如下所示)来使用。如果需要细粒度控制,这比禁用文件中的所有内容都要细粒度。
Tested with Visual Studio 2015 Update 3 and ReSharper Ultimate 10.0.2
使用Visual Studio 2015 Update 3和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");
}
}
#6
2
You can add the file to the list of "Generated Code" in ReSharpers Options Menu:
您可以将该文件添加到ReSharpers选项菜单中的“生成代码”列表中:
Options > CodeInspection > Generated Code
#1
35
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.
根据JetBrains博客上的这篇文章,在ReSharper 8中会有一个注释可以在文件中禁用ReSharper。
It will be
这将是
// ReSharper disable All
Note: The "All" is case-sensitive, the rest is not.
注意:“All”是区分大小写的,其余则不是。
#2
41
Nial, you can press Ctrl + Shift + Alt + 8 to disable analyses and highligtings in current file.
Nial,您可以按Ctrl + Shift + Alt + 8来禁用当前文件中的分析和增强。
#3
5
The following worked for me.
以下是我的工作。
- Add "No Resharper" to Generated Code Regions in R# -> Options -> Code Inspection -> Generated Code
- 在r# ->选项->代码检查->生成的代码中添加“无Resharper”
-
Use the following to suppress the warnings:
使用以下方法来抑制警告:
#region No Resharper // All R# warnings are suppressed here #endregion
#4
2
you have to configure the ReSharper Inspections
你必须配置锐化检查
http://www.jetbrains.com/resharper/webhelp/Code_Analysis__Configuring_Warnings.html
http://www.jetbrains.com/resharper/webhelp/Code_Analysis__Configuring_Warnings.html
#5
2
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.
您还可以使用ReSharper作为类别和所有作为该方法或类的checkId(如下所示)来使用。如果需要细粒度控制,这比禁用文件中的所有内容都要细粒度。
Tested with Visual Studio 2015 Update 3 and ReSharper Ultimate 10.0.2
使用Visual Studio 2015 Update 3和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");
}
}
#6
2
You can add the file to the list of "Generated Code" in ReSharpers Options Menu:
您可以将该文件添加到ReSharpers选项菜单中的“生成代码”列表中:
Options > CodeInspection > Generated Code