Stop ReSharper from Adding Annotations

允我心安 提交于 2019-12-09 14:20:20

问题


I'm using ReSharper in my C# projects, and generally I love it. However, it keeps adding annotations to the code when I do certain refactoring actions.

For example, it adds [NotNull] when I use the "Check parameter for null" context action:

// Before context action
public void Foo(object input)
{
}

// After context action
public void Foo([NotNull] object input)
{
    if (input == null)
    {
        throw new ArgumentNullException("input");
    }
}

Additionally, ReSharper then adds using JetBrains.Annotations to the file, even though I'm not referencing the JetBrains assembly where the attribute is defined.

I would like to continue using the context actions, as they're very useful, but I can't introduce external annotations in the code. ReSharper provides an option to change the default annotation namespace and to copy the annotation attribute source code into your project, but that also isn't an option for this project.

Is there any way to tell ReSharper to stop adding annotations entirely? I've tried in the options unchecking JetBrains.Annotations as a namespace with code annotation attributes, but that doesn't seem to have any effect on whether the annotations are generated in the first place.

Update: While I wasn't actually referencing JetBrains.Annotations.dll, I was referencing another DLL that re-implemented the same annotation attributes in the same JetBrains.Annotations namespace. Removing that DLL reference will prevent ReSharper from adding the annotations. It'd be nice if there was still an option to turn this off, but the workaround fits for this situation.


回答1:


When you reference the JetBrains.Annotations.dll, the default action for "Check parameter for null" seems to be to use the NotNull attribute (despite adding an "Annotate with 'NotNullAttribute'" option.

The only workaround that I know is to not reference JetBrains.Annotations.dll.

Update:

looking more into this, it seems that there was a suggestion/bug that [NotNull] be added when the annotations dll is included and "Check parameter for null" is requested: http://youtrack.jetbrains.com/issue/RSRP-70350 In case anyone else happens across this and wonders why...



来源:https://stackoverflow.com/questions/15485338/stop-resharper-from-adding-annotations

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