I have an enum which describes options available for a user to select as part of settings. This is serialized to XML. One of the names is not ideal, and I'd like to rename it, but still support deserialization of older settings files.
For example:
public enum Options
{
Odd,
NonOdd // rename to 'Even'
}
I know I can rename it but specify the previous serialized name like this:
public enum Options
{
Odd,
[XmlEnum(Name = "NonOdd")]
Even
}
While this works, it continues to use NonOdd
in the XML file, which I would prefer not to do.
Is there a way to support deserialization of current and deprecated enum names, but serialize to the current name?
Here's what I would do:
Once you have this structure in place you can rename enum elements as many times as you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With