我想为分层结构对象创建一个抽象类。分层结构对象的通用抽象类
以下是我已经使用,但现在我想使它通用
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