我有以下类/接口:
public abstract class AbstractBasePresenter<T> : IPresenter<T>
where T : class, IView
{
}
public interface IPresenter<T>
{
}
public interface IView<TV, TE, TP> : IView
where TV : IViewModel
where TE : IEditModel
//where TP : AbstractBasePresenter<???>
{
}
public interface IView {}
有什么方法可以将 IView<> 上的 TP 限制为从 AbstractBasePresenter 继承的类?
还是我唯一的选择是创建一个非通用 IPresenter 接口,然后更新 IPresenter 以实现它,然后使用检查“TP:IPresenter”?
谢谢
更新:
以下建议的答案不起作用:
public interface IView<TV, TE, TP> : IView
where TV : IViewModel
where TE : IEditModel
where TP : AbstractBasePresenter<IView<TV,TE,TP>>
{
}
我将接口声明为:
public interface IInsuredDetailsView : IView<InsuredDetailsViewModel, InsuredDetailsEditModel, IInsuredDetailsPresenter>
{ }
public interface IInsuredDetailsPresenter : IPresenter<IInsuredDetailsView>
{ }
编译器抱怨 IInsuredDetailsPresenter 不能分配给 AbstractBasePresenter>