【发布时间】:2015-12-08 20:39:56
【问题描述】:
我有一个
public class A<T> where T : IBase
{
//Does something
}
我需要第二个类,其行为类似于 A 类的集合
public class B<A<T>> : IEnumerable<A<T>> where T : IBase
{
}
问题是我不想创建类似的类
public class B<A<MyCustomObjectP>> : IEnumerable<A<MyCustomObjectP>>
{
}
public class C<A<MyCustomObjectQ>> : IEnumerable<A<MyCustomObjectQ>>
{
}
等等..我想让CustomObject成为实现IBase的泛型类型参数。
我发现即使这样做也是违法的:
public class B<T, U> : IEnumerable<T> where T : A<U> where U : IBase
{
}
如果这是非法的,我该如何实现这种行为?是否有更好的设计模式可能会有所帮助?
【问题讨论】: