I know the following is not possible because it has to be an int
enum GroupTypes
{
TheGroup = "OEM",
TheOtherGroup = "CMB"
}
From my database I get a field with incomprehensive codes (the OEM and CMB's). I would want to make this field into an enum or something else understandable. Because the target is readability the solution should be terse.
What other options do I have?
How about using a static class with constants? The client code will look no different from enums.
Create a second enum, for your DB containing the following:
Now, you can use Enum.Parse to retrieve the correct DBGroupTypes value from the strings "OEM" and "CMB". You can then convert those to int and retrieve the correct values from the right enumeration you want to use further in your model.
If I understand correctly, you need a conversion from string to enum:
You can make it more fancy with generics for the enum type if you wish.
This is a way to use it as a strongly typed parameter or as a string :
You can do it very easily actually. Use the following code.
Then when you want to get the string value of each enum element just use the following line of code.
I've used this method successfully in the past, and I've also used a constants class to hold string constants, both work out pretty well, but I tend to prefer this.
I would just create a dictionary and use the code as the key.
Edit: To address the comment about doing a reverse lookup (finding the key), this would not be terribly efficient. If this is necessary, I would write a new class to handle it.