我想爲分層結構對象創建一個抽象類。分層結構對象的通用抽象類
以下是我已經使用,但現在我想使它通用
public class EventBase
{
private EventBase _Parent;
virtual public EventBase Parent
{
get
{
return _Parent;
}
set
{
_Parent = value;
}
}
[ForeignKey("Parent")]
private ICustomList<EventBase> _ChildList = new CustomList<EventBase>();
virtual public ICustomList<EventBase> ChildList
{
get
{
return _ChildList;
}
set
{
_ChildList = value;
}
}
}
是這樣的:
public class EventBaseGeneric
{
private GenericTypeThatIsSetInTheInheritingClass _Parent;
virtual public GenericTypeThatIsSetInTheInheritingClass Parent
{
get
{
return _Parent;
}
set
{
_Parent = value;
}
}
[ForeignKey("Parent")]
private ICustomList<GenericTypeThatIsSetInTheInheritingClass> _ChildList = new CustomList<GenericTypeThatIsSetInTheInheritingClass>();
virtual public ICustomList<GenericTypeThatIsSetInTheInheritingClass> ChildList
{
get
{
return _ChildList;
}
set
{
_ChildList = value;
}
}
}
非常感謝如何achiv這個任何想法!
最好的問候, Fabianus
檢查煤礦,它採用通用約束。 –
而且我還重構了代碼以使用自動屬性和屬性初始值設定項。 –
嘿@MatíasFidemraizer - 非常感謝你!這正是我所需要的。我的回答只是一半的方式.... – Fabianus