I have an enumeration value marked with the following attribute. The second parameter instructs the compiler to error whenever the value is used. I want this behavior for anyone that implements my library, but I need to use this enumeration value within my library. How do I tell the compiler to ignore the Obsolete error for the couple of uses in my library.
public enum Choices { One, Two, [ObsoleteAttribute('don't use me', true)] Three, Four }
Solution (Thanks everyone)
public class EnumHack { static EnumHack() { // Safety check if (Choices!= (Choices)Enum.Parse(typeof(Choices), 'Three')) throw new Exception('Choices.Three != 3; Who changed my Enum!'); } [Obsolete('Backwards compatible Choices.Three', false)] public const Choices ChoicesThree = (Choices)3; }
Private a separate constant somewhere like this:
Note that anyone else will be able to do the same thing.