I&QUOT可以;修复"错误的ReSharper的注解? [英] Can I "fix" wrong Resharper annotations?
问题描述
我喜欢ReSharper的,但有时会产生不正确的警告,可能是因为BCL类型内置批注是错误的。例如,在此code:
I love Resharper, but sometimes it gives incorrect warnings, probably because the built-in annotations for BCL types are wrong. For instance, in this code:
private static string GetDescription(T value)
{
Type type = typeof(T);
string name = Enum.GetName(type, value);
if (name != null)
{
...
这让我对如果
声明警告:前pression总是正确的。但 Enum.GetName
可以返回空值:
It gives me a warning on the if
statement: "Expression is always true". But Enum.GetName
can return null:
string name = Enum.GetName(typeof(DayOfWeek), (DayOfWeek)42); // null
我想这是因为有一个 [NOTNULL]
标注为 Enum.GetName
。有没有办法来解决这个问题,所以我没有得到警告?
I assume this is because there is a [NotNull]
annotation for Enum.GetName
. Is there a way to fix that so I don't get the warning?
的注:我使用ReSharper的5.1;也许这个问题是固定在6版本,但我不愿意现在就升级。的
推荐答案
OK,我知道了。内置的注释在ReSharper的安装目录(XML文件中定义的 C:\\ Program Files文件(x86)的\\ JetBrains的\\ ReSharper的\\ V5.1 \\ BIN \\ ExternalAnnotations \\
我的机器上)。解决方法是编辑相应的文件删除或修正不正确的注释。
OK, I got it. The built-in annotations are defined in XML files in the Resharper installation directory (C:\Program Files (x86)\JetBrains\ReSharper\v5.1\Bin\ExternalAnnotations\
on my machine). The solution is to edit the appropriate file to remove or fix the incorrect annotations.
在 Enum.GetName
的情况下,更改文件是 mscorlib程序\\ mscorlib程序。[版] .Contracts.xml
。我只是评论此注释:
In the case of Enum.GetName
, the file to change is mscorlib\mscorlib.[version].Contracts.xml
. I just commented this annotation:
<member name="M:System.Enum.GetName(System.Type,System.Object)">
<attribute ctor="M:JetBrains.Annotations.NotNullAttribute.#ctor" />
</member>
和重新启动Visual Studio中,现在警告了:)
And restarted Visual Studio, and now the warning is gone :)
这篇关于I&QUOT可以;修复&QUOT;错误的ReSharper的注解?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!