我有一个基础通用类,看起来是这样的扩展限制:继承和泛型
public abstract class BaseTestDataEntity<T>
where T : IIdEntity, ICodeEntity, IActiveEntity, new()
{
}
这些接口代表了数据entities.This领域是非常有用的,因为使用这些接口,我可以写了通用基础类它可以有像添加,更新等方法。
但真正有用的是全面的设计时间支持基于接口的合同。
一个实例的一个例子:
public class Customer : BaseTestDataEntity<Customer>
{}
现在我有一个情况,我想建立派生类BaseTestDataEntity的,其中将包括基地的所有约束(因此每个代码,T必须有ID,代码和活动标志)
但是,在派生类中,我想添加其他约束。
这样我就不必在BaseTestDataEntity中重复具体的方法。
我试图和我想做的事:
public class BaseTestDataEntityImpl<T>
: BaseTestDataEntity<T> where T : IIdEntity, ICodeEntity, IMultiTextEntity, IActiveEntity, new()
{
// This should enforce T constaints in the base class, but where do I put in new constraints in the derived T?
}