Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop ReSharper from Adding Annotations

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.

like image 392
Andy Magee Avatar asked Mar 18 '13 19:03

Andy Magee


1 Answers

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...

like image 62
Peter Ritchie Avatar answered Oct 14 '22 19:10

Peter Ritchie