how to derive xml element name from an attribute value of a class using annotations?



I have properties that have ids and values and a name. Can I represent all those with a single class using XElement/XmlArray C# annotations? I would like to derive the xml element name from the class attribute name;


my class would look like:



public class Property {
public string name; //could be enum
public int id;
public string value;
}


e.g:



new Property("property1name",2,"testvalue");
new Property("property2name",10,"anothervalue");


I would like to have xml that looks like:



<property1name><id>2</id><value>testvalue</value></property1name>
<property2name><id>10</id><value>anothervalue</value></property2name>


instead of the usual



<property><name>property1name</name><id>2</id><value>testvalue</value></property>
<property><name>property2name</name><id>10</id><value>anothervalue</value></property>


In other words the xmlelement gets its name from attribute name of the class Property


No comments:

Post a Comment