2011-10-24 40 views
2

我用XMLSerialiser反序列化我的泛型类时遇到了问题。 这里是一些代码使用列表反序列化泛型类<T>

[XmlInclude(typeof(OrderProposalsProductGroupData<OrderProposalsProductGroupProposals>))] 
public class OrderProposalsStoreProductGroups<TU> : OrderProposalsStore<TU> where TU : class 
{ 

    #region properties 

    /// <summary> 
    /// TODO 
    /// </summary> 
    [XmlElement("groups")] 
    /* BUG: This list is not fully filled during deserialisation. Only one entry is added although the stream does definetly have more entries. Why the hell? It works with all other classes in our logic but not here. 
    * Maybe the deserializer has problems with the generic nature? but I couldn't find any such issue reported anywhere in the internet or any 
    restriction description concerning generics (in fact I found a bunch of examples using generics with the Deserialiser). Actually the MS XMLSerializer description confirms 
    that any class implementing an IEnumerable or ICollection can be deserialized so it makes no sense it doesn't work. Anybody a clue? */ 
    public List<TU> ProductGroups { get; set; } 

    #endregion 

} 

有没有人遇到类似的行为。有趣的是,对象(即添加到上面的列表中)正确填充了我们正在处理的XML流中的适当数据。

这可能是值得炫耀实现上述类的类,它本身也是一个通用类

public class OrderProposalsStores<T> : EntityBase where T : new() 
{ 

    #region properties 

    [XmlElement("Store")] 
    public T OrderProposalsStore 
    { 
     get; 
     set; 
    } 

    #endregion 
} 

以及物品是否完整在这里的列表中的类

[Serializable, 
XmlInclude(typeof(OrderProposalsProductGroupProposals))] 
public class OrderProposalsProductGroupData<TU> : EntityBase where TU : OrderProposalsProductGroup 
{ 
    #region properties 

    [XmlElement("productgroup")] 
    public TU ProductGroup { get; set; } 

    #endregion 

} 

我很好意识到XMLArray和XMLArrayItem,但这是代码中使用的结构,它在我们使用的所有其他代码中都像一个魅力一样,所以我们将保持一致(好,并且截止日期与我接近......) 。无论如何,这是我的意见,它应该以任何方式工作,我不知道为什么它不。

我很欣赏任何输入或帮助。

在此先感谢

回答

1

尝试使用XmlArray属性改为:

[XmlArray("List")] 
public List<T> MyList { get; set; } 
+0

与XmlArray简单地更换不起作用!这一点完全停止了反序列化。 –