I am trying to serialize a class object in xml that looks like this:
<Colors> <Blue> <R>0,000</R> <G>0,000</G> <B>1,000</B> <A>1,000</A> </Blue> <Red> <R>1,000</R> <G>0,000</G> <B>0,000</B> <A>1,000</A> </Red></Colors>
The important part is that the colors of blue and red are not directly indicated. I have a class like this:
public class Color { [XmlElement("R")] public string red; [XmlElement("G")] public string green; [XmlElement("B")] public string blue; [XmlElement("A")] public string alpha; }
I need a way to instantiate an object of the Color class and serialize it with different names, for example blue, red, green, anothercolor1, anothercolor2, ... it should also be possible to dynamically add new colors at runtime.
I know that I can add attributes to the Color class, but I cannot change the xml layout, so I need to find another way.
Any ideas?
source share