我有一個基礎通用類,看起來是這樣的擴展限制:繼承和泛型
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?
}