我是C#的新手(我是Java开发人员)并且对泛型有个疑问。我有一个嵌套类泛型类:我该如何扩展嵌套在另一个泛型类中的类?
public class FlowChartBuilder<TEntity, TLink>
where TEntity : FlowChartBuilder<TEntity, TLink>.Entity
where TLink : FlowChartBuilder<TEntity, TLink>.Link
{
public abstract class Link { }
public abstract class Entity { }
}
下一个我试图扩展这些类:
public class ChartEntity<T>: FlowChartBuilder<ChartEntity<T>, ChartLink>.Entity
{
}
public class ChartEntity<T>: FlowChartBuilder<ChartEntity<T>, ChartLink<ChartEntity<T>>>.Entity
{
}
但我得到一个错误:
"TEntity" type can't be used like a parameter of "TEntity" type in the universal type or method "FlowChartBuilder". There isn't a transformation-packaging or a transformation of a type parameter from the "TEntity" to the "PM.Utils.Diagram.FlowChartBuilder>.Entity".
怎么写正确?
将是冷静,如果你可以用英语发表您的错误 –
对不起,我刚才没有注意到。我已经翻译过了。 –
我认为这是一个重复的这个http://stackoverflow.com/questions/21566701/nested-class-that-inherits-from-its-generic-parent-class可能你会发现你的答案。它告诉用继续代替继承。 –