How can I disable a single ReSharper "Parameter Can Be of Type" suggestion?

611 Views Asked by At

ReSharper is flagging a constructor parameter with a warning, suggesting that I change the parameter to it's inherited interface type. However I need the specific implementation as the parameter type for dependency injection reasons.

I can't seem to disable this individual suggestion. // ReSharper disable All + // ReSharper restore All did not appear to work and none of the drop down options let me ignore it.

My code is arranged somewhat like this:

// Constructor with the ReSharper warning.
IShape _shape;
public SquareConsumer(Square square){
    _shape = square;
}

// Class where I set up dependency injection using Ninject.
public void SetupBindings(IKernel kernel){
    kernel.Bind<Square>.ToSelf();
    kernel.Bind<SquareConsumer>.ToSelf();
}

I realize that I could use a more generic binding and bind "IShape" to "Square" when injected in to the "SquareConsumer", but in the context of my application it makes more sense to have a single instance of "Square" available to any class that needs to use it explicitly.

I am using ReSharper 8.2 and Visual Studio 2013 (Professional).

How can I disable this instance of the warning?

2

There are 2 best solutions below

0
ulrichb On BEST ANSWER

To specifically suppress the "Parameter can be declared with base type" warning, use

// ReSharper disable once SuggestBaseTypeForParameter
1
xtu On

If you just want to ignore this warning, click the gear icon on the left of the constructor line of code and select 'Inspection' - 'Disable Once with Comment'.