public static T CastToEnum<T>(string name)
{
if (Enum.IsDefined(typeof(T), name))
{
return (T)Enum.Parse(typeof(T), name);
}
else
{ //No enum for string name
throw new ArgumentOutOfRangeException(
string.Format("{0}...{1}", name, typeof(T).ToString()));
}
}