Reputation: 19
I have a problem with a generic class of mine that I am deserializing with the XMLSerialiser. Here is some code
[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
}
Did anybody encounter a similar behavior. The funny thing is that the object (that is added to the above List) is correctly filled with the appropriate data from the XML stream we are processing.
It may be worth showing the class that implements the above class, which is itself also a generic class
public class OrderProposalsStores<T> : EntityBase where T : new()
{
#region properties
[XmlElement("Store")]
public T OrderProposalsStore
{
get;
set;
}
#endregion
}
And for completeness here the class in the list
[Serializable,
XmlInclude(typeof(OrderProposalsProductGroupProposals))]
public class OrderProposalsProductGroupData<TU> : EntityBase where TU : OrderProposalsProductGroup
{
#region properties
[XmlElement("productgroup")]
public TU ProductGroup { get; set; }
#endregion
}
I am well aware of XMLArray and XMLArrayItem but this is the structure that has been used in the code and it works like a charm in all the other code we use so we would to remain consistent.
Upvotes: 1
Views: 161
Reputation: 46047
Try using the XmlArray
attribute instead:
[XmlArray("List")]
public List<T> MyList { get; set; }
Upvotes: 1