我需要从我的班级收到的对象创建一个列表。但我不能这样做?
[XmlTypeAttribute(AnonymousType = true)]
public class PackIt
{
[XmlElement("pack")]
public List<object> objects { get; set; }
public PackIt(object model)
{
objects = new List<model.GetType()>();
}
}
答案 0 :(得分:0)
您可以PackIt
通用:
[XmlTypeAttribute(AnonymousType = true)]
public class PackIt<T>
{
[XmlElement("pack")]
public List<T> objects { get; set; }
public PackIt()
{
objects = new List<T>();
}
}
PachIt<string> packIt = new PackIt<string>();