IAM试图创建一个通用存储库为我查找对象,并写:摘要泛型类的泛型约束
public interface ILookupRepository<T> :
IDisposable,
ICanGetAll<T>,
ICanGetById<T, int>
where T: LookUpObject
{
}
ICan...
的接口定义粒状操作库,这样我可以使用组合来定义行为
我想限制这个接口只为我查找对象,所以我用的是where T: LookUpObject
约束
这是抽象类:
public abstract class LookUpObject<TObject, TKeyType> : IKeyedEntity<TKeyType>
where TObject : class
where TKeyType : struct
{
private TKeyType id;
private string description;
private bool valid;
public TKeyType Id
{
get { return id; }
set { id = value; }
}
public string Description
{
get { return description; }
set { description= value; }
}
public bool Valid
{
get { return valid; }
set { valid= value; }
}
protected LookUpObject()
{
}
}
,但我不知道如何在我的回购类中定义的约束:
我尝试
public interface ILookupRepository<T> :
IDisposable,
ICanGetAll<T>,
ICanGetById<T, int>
where T: LookUpObject<T1, TkeyType> where T1: class
where TkeyType: Type
,但它不承认T1
和TkeyType
是可能的事情?
编辑
溶液@Grax与TkeyType的不是int关键
public interface ILookupRepository<T, TkeyType> :
IDisposable,
ICanGetAll<T>,
ICanGetById<T, TkeyType>
where T : LookUpObject<T, TkeyType>
where TkeyType : struct
这可能只是'T1'和'TKeyType'需要在'ILookupRepository'上。不完全确定。 – Magus