I need to deserialize/serialize XML which looks like this:
<color>
<green/>
</color>
where <green/>
may be <red/>
, <blue/>
etc. - very large (but limited) set.
I'd like to describe it as simple enum in my code:
enum ColorName
{
[XmlEnum("red")]
Red,
[XmlEnum("green")]
Green,
[XmlEnum("blue")]
Blue,
...
etc.
}
But, if I write my object model like this:
class Color
{
[XmlElement("name")]
public ColorName ColorName;
}
class Something
{
[XmlElement("color")]
public Color Color;
}
enum gets into XML as a value, rather than element name:
<color>
<name>green</name>
</color>
Is there any way to get enum value written into XML element name (see the first XML snippet - that's the goal), rather than XML element value, without having to re-type all the values (it's a very large set) as empty class names, or resorting to custom serialization (I would like to avoid it, because serialized class contains a lot of other members, which are perfectly serialized by default)?
(I can't change the schema, it's third-party).