Map list value to another list based on predefined relation in C#
If you need to be able to perform the conversion in both directions, you could achieve this using two enums - one for each form - in the same order. For example:
public enum ColorLong
{
Red,
Green,
...
}
public enum ColorShort
{
RD,
GR,
...
}
To map from one form to the other, just parse the string input to the proper enum type with a case-insensitive parse and then cast that result to the target enum type.
When you parse the string to the source type enum, you are actually getting an integer value that corresponds to the elements position in the enum (by default). As long as both enums have their values in the same order, this will work just fine. No conditional logic or switch statements required!
As an example, to parse from the long form to the short form:
var longForm = Enum.Parse<ColorLong>(inputString, true);
var shortForm = (ColorShort) ((int)longForm);