Lets say for maintenance and DataContract serialization i need to add the default value 0 to an existing enum where it wasn't present.
public enum ExistingEnum { Value1 = 1, Value2 = 2, Value3 = 3 } Becomes:
public enum ExistingEnum { None = 0, Value1 = 1, Value2 = 2, Value3 = 3 } All the properties that relied on taking the Value1 as default value are now causing a chain of problems and related Exceptions. Is there a way, like an attribute, to impose Value1 as the default value, again? Something similar to:
public enum ExistingEnum { None = 0, [Default] Value1 = 1, Value2 = 2, Value3 = 3 } Thanks in advance
Console.WriteLine(default(ExistingEnum))on the precchanged enum it just prints0which is what I would expect the default value to be. The fact it doesn't have any meaning doesn't make a difference. See for example stackoverflow.com/questions/529929/… . If your code was defaulting toValue1before you must have some code to do that. Perhaps if you share this code we can help you modify it (or maybe you can do it yourself once you find it).0regardless of if that value has a matching enum member.