I want to define a flag enum like the following:
[Flags]
[Serializable]
public enum Numbers
{
[XmlEnum(Name = "One")]
One = 0x1,
[XmlEnum(Name = "Two")]
Two = 0x2,
[XmlEnum(Name = "Three")]
Three = 0x4,
[XmlEnum(Name = "OddNumbers")]
OddNumbers = One | Three,
[XmlEnum(Name = "EvenNumbers")]
EvenNumbers = Two,
[XmlEnum(Name = "AllNumbers")]
AllNumbers = One | Two | Three
}
Suppose I create an object which has a Numbers
property and I set that property to EvenNumbers
. Today, only Two
is included in property, but I want to specify EvenNumbers
so that if I add Four
in the future it will be included in the property as well.
However, if I serialize this object using XmlSerializer.Serialize
, the XML will say Two
because today this is the same underlying value.
How can I force the serializer to serialize this property as EvenNumbers
?