My enum consists of the following values:
private enum PublishStatusses{
NotCompleted,
Completed,
Error
};
I want to be able to
I created a reverse extension method to convert the description back into an enum value:
public static T ToEnumValue(this string enumerationDescription) where T : struct
{
var type = typeof(T);
if (!type.IsEnum)
throw new ArgumentException("ToEnumValue(): Must be of enum type", "T");
foreach (object val in System.Enum.GetValues(type))
if (val.GetDescription() == enumerationDescription)
return (T)val;
throw new ArgumentException("ToEnumValue(): Invalid description for enum " + type.Name, "enumerationDescription");
}