I hate ugly code like this:
MyEnum enumValue = (MyEnum) Enum.Parse(typeof (MyEnum), stringValue);
Too many casts for my taste. Here's my answer (and yes it's so simple that I am embarrassed to post it, but just in case you haven't thought of it yet...)
public static class Enum<T>
{
public static T Parse(string value)
{
return (T) Enum.Parse(typeof (T), value);
}
public static IList<T> GetValues()
{
IList<T> list = new List<T>();
foreach (object value in Enum.GetValues(typeof (T)))
{
list.Add((T) value);
}
return list;
}
}
So the ugliness is converted to
MyEnum enumValue = Enum<MyEnum>.Parse(stringValue);