0

ReSharper 正在使用警告标记构造函数参数,建议我将参数更改为其继承的接口类型。但是,出于依赖注入的原因,我需要特定的实现作为参数类型。

我似乎无法禁用这个单独的建议。// ReSharper disable All+// ReSharper restore All似乎不起作用,并且没有一个下拉选项让我忽略它。

我的代码安排得有点像这样:

// 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();
}

我意识到当注入到“SquareConsumer”时,我可以使用更通用的绑定并将“IShape”绑定到“Square”,但在我的应用程序的上下文中,让“Square”的单个实例可用于任何需要显式使用它的类。

我正在使用 ReSharper 8.2 和 Visual Studio 2013(专业版)。

如何禁用此警告实例?

4

2 回答 2

2

要专门抑制“参数可以用基类型声明”警告,请使用

// ReSharper disable once SuggestBaseTypeForParameter
于 2015-10-06T23:19:57.390 回答
0

如果您只想忽略此警告,请单击构造函数代码行左侧的齿轮图标,然后选择“检查”-“使用注释禁用一次”。

于 2015-10-06T20:32:40.550 回答