我有一个实体类的基类
public class Entity<T> where T : Entity<T>, new()
{
public XElement ToXElement()
{
}
public static T FromXElement(XElement x)
{
}
}
我必须使用这种奇怪的结构 Entity<T> where T : Entity<T>
,因为我想让静态方法FromXElement具有强类型。
另外,我有一些实体,就像这样
public class Category : Entity<Category>
{
}
public class Collection : Entity<Collection>
{
}
如何使用基类创建我的实体的通用列表?
var list = new List<Entity<?>>();
list.Add(new Category());
list.Add(new Collection());