I am trying to create a c# object for serialization/deserialization with a string property.
The property needs to generate an element and also have an attribute:
eg:
...
<Comment Name="CommentName"></Comment>
...
If the property is a string, I cant see how to add the attribute, and if the comment is an object with Name and Value properties it generates:
...
<Comment Name="CommentName">
<Value>comment value</Value>
</Comment>
...
Any ideas?
You would need to expose those 2 properties on a type and use the
[XmlText]attribute to indicate that it shouldn’t generate an extra element:If you want to flatten those properties onto the object itself (the
Customerinstance in my example), you would need extra code to make the object model pretend to fit whatXmlSerializerwants, or a completely separate DTO model.