I have an enum that enumerates integer values returned from an external API for easier use in my code. But I don't necessarily know the integer values at compile time, so I have some code that hooks them up at program start and stores them in a Dictionary.
I've defined some extension methods for conversion to/from the integer codes, but these integer codes aren't the same as what would be returned from a cast to int. If another programmer were to program with my enum I'm afraid they'd try casting to and from integers out of force of habit. And the program would just silently accept the bad code.
Is there a way to prevent explicit conversion of my enum to/from int? If not, is there a way to cause an exception to be thrown if someone tries? Or hook up my own conversion functions? Or change the underlying value of an enum at run time?