I have a .NET Web API project where I have a Data Transfer Object Class which I want to serialize to XML.
The class (simplified) is basically defined as follows:
[XmlType("user")]
public class PublicVisibleUserDTO
{
public long id { get; set; }
public string screenname { get; set; }
}
Now, when I call a function that returns only one element, I get good and proper XML as I expect:
<user>
<id>123</id>
<screenname>john</screenname>
</user>
However, when I have a function that returns a collection of this Data Transfer Object I get:
<ArrayOfUser>
<user>
<id>123</id>
<screenname>john</screenname>
</user>
<user>
<id>124</id>
<screenname>jane</screenname>
</user>
</ArrayOfUser>
But what I want is:
<users>
<user>
<id>123</id>
<screenname>john</screenname>
</user>
<user>
<id>124</id>
<screenname>jane</screenname>
</user>
</users>
So basically I want the collection to be returned as "types" (users) rather than "ArrayOfType" (ArrayOfUser). How do I do this?
I have tried applying an XmlArray/XmlArrayAttribute function at the top of the class declaration, but that cannot be applied to a class definition.