Skip to content

Instantly share code, notes, and snippets.

@mariusz
Created January 19, 2009 19:35
Show Gist options
  • Save mariusz/49124 to your computer and use it in GitHub Desktop.
Save mariusz/49124 to your computer and use it in GitHub Desktop.
public static List<T> EnumToList<T>()
{
Type enumType = typeof(T);
if (enumType.BaseType != typeof(Enum))
throw new ArgumentException("T must be of type System.Enum");
Array enumValArray = Enum.GetValues(enumType);
List<T> enumValList = new List<T>(enumValArray.Length);
foreach (int val in enumValArray)
{
enumValList.Add((T)Enum.Parse(enumType, val.ToString()));
}
return enumValList;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment