2013-10-17 173 views
0

我需要從我的課程收到的對象中創建一個列表。但我做不到?從收到的對象創建列表?

[XmlTypeAttribute(AnonymousType = true)] 
public class PackIt 
{ 

    [XmlElement("pack")] 
    public List<object> objects { get; set; } 

    public PackIt(object model) 
    { 
     objects = new List<model.GetType()>(); 
    } 

} 

回答

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>();