我是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可能你會發現你的答案。它告訴用繼續代替繼承。 –