I am keeping a static dictionary to map a simple integer stored in a database to an enum value.
static Dictionary<long, EModelType> AttributeIdTypeToEModelType =
new Dictionary<long, EModelType>()
{
{1, EModelType.StatStr},
{6, EModelType.HistStr},
{7, EModelType.HistVal}
};
The great advantage is that I use it to directly get my enum value as the data arrive from the database.
typ = AttributeIdTypeToEModelType[i];
The usage of this system is neat, but it doesn’t look clean to me to have a static dictionary just for this.
I had no chance trying to find a cleaner way to use enumerators and overriding their values.
Any advice?
You don’t need a
Dictionaryto cast anintto the appropriateEnumtype:or using
Enum.ToObject:and you can check that it exists with
Enum.IsDefined: