xml serialization of a List without a Class object
So I am familar with the XmlArray Att开发者_如何转开发ribute and it works great when I am serializing a Class, but now I am tasked with just serializing a piece of a class, a List of Int to be exact
<Serializable()> _
Public Class InvoiceList
<XmlArray("InvoiceList")> _
<XmlArrayItem("InvoiceId")> _
Public m_List As List(Of Integer)
If I serialize the entire class the alias works great but if I do
serializer = New XmlSerializer(m_List.GetType())
serializer.Serialize(stream, m_List)
I get the
<ArrayOfInt>
<int>
How can I apply a alias just to a property?
I am looking for
<InvoiceList>
<InvoiceId>
You need to use
XmlSerializer Constructor (Type, XmlAttributeOverrides)
which allows you to specify the xml attributes, you could either read them using reflection from your example class - or specify them explicitly.
http://msdn.microsoft.com/en-us/library/bfaxz1a0.aspx
The problem was that by specify type to list the attributes of your class are unknown - they belong only to your class
精彩评论