I'm attempting to serialize a List<T> of some custom classes with:
List<T> l = new List<T>();
...
XmlSerializer serializer = new XmlSerializer(l.GetType());
serializer.Serialize(writer, list);
And it outputs:
<ArrayOfT>
<T>
...
</T>
<T>
...
</T>
</ArrayOfT>
How do I get the same thing, but without the ArrayOfT elements, so it would look like:
<T>
...
</T>
<T>
...
</T>
I'm attempting to do this because it's happening in a wrapper class so my actual output is coming in the format of:
<PropertyName>
<ArrayOfT>
<T>
...
</T>
<T>
...
</T>
</ArrayOfT>
</PropertyName>
And the ArrayOfT element is redundant (logically it would have the same name as PropertyName.)
[XmlElement("T")]attribute iflis a property in a class.ArrayOfTelement, not rename it, alsolis not a property, it is a variable within an implementation ofIXmlSerializable.WriteXml(XmlWriter writer)which is in the class which makes up the property.