我在使用XMLSerialiser反序列化我的泛型类时遇到问题。 这是一些代码
[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
}
是否有人遇到过类似的行为。有趣的是,对象(添加到上面的List中)正确填充了我们正在处理的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,但这是在代码中使用的结构,它在我们使用的所有其他代码中就像一个魅力所以我们将保持一致(好吧,截止日期即将到来)与我一起...)。无论如何,我认为它应该以任何方式工作,我不知道为什么它不会。
我感谢任何意见或帮助。
提前致谢
答案 0 :(得分:1)
请尝试使用XmlArray
属性:
[XmlArray("List")]
public List<T> MyList { get; set; }