As we know, all enums are compiled as constants, which means you can get unexpected results if you use an enum from a different assembly.
Settings sequential enum numbers explicitly is no help, because if you want to leave room for new values, you have to do basic-linenumber-style spacing, which is naff.
So I wondered about using the hashcode of the Enum value name as string, which is fairly easy to generate a script for.
Is this a good idea? Will I have problems with the negative values that hashcode can return?
EDIT For those asking why, I quote the linked "corner case":
Given an assembly with:
enum MyEnum
{
Red,
Blue,
}
if you use MyEnum.Red.ToString() in another assembly, and in between times someone has recompiled your enum to:
enum MyEnum
{
Black,
Red,
Blue,
}
at runtime, you will get "Black".
(NB, I am not especially interested in the ToString here, the problem is that if calling code asks for MyEnum.Red, it's actually referencing MyEnum.Black)
Another example to illustrate the problem with explicit sequential numbering:
enum ECountry
{
Afghanistan = 1,
Barbados = 2,
Chile = 3,
...
Zambia = 243,
}
If Giggleswick suddenly declares itself a republic, what do you do?