【发布时间】:2016-03-22 18:59:32
【问题描述】:
我有 2 个使用泛型的接口
我的子界面如下所示:
public interface ICell<TContent>
{
TContent Content { get; }
string Background { get; }
string Foreground { get; }
}
和我的父界面如:
public interface IRow<TRowHeader,TContent>
{
TRowHeader RowHeader { get; }
IList<ICell<TContent>> Zellen {get;}
}
当我基于 IRow 创建一个类时,我必须设置我想要避免的 TContent。所以我想知道如何从我的IRow 中抽象出这个泛型?
最后我希望能够写作
public class MyCell : ICell<string>
{
public string Background { get; set; }
public string Content { get; set; }
public string Foreground { get; set; }
}
public class MyRow: IRow<string,MyCell>
{
public string RowHeader { get; set; }
public IList<MyCell> Zellen { get; set; }
}
【问题讨论】:
-
你需要使用不同的接口,你不能只是省略泛型参数并替换具体类。你为什么不做类似
MyRow : IRow<string, MyCell>的事情? -
@RonBeyer 谢谢我会更新我的问题
标签: c# generics design-patterns interface