Created
January 19, 2009 19:35
-
-
Save mariusz/49124 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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