星期四, 六月 26, 2008

Generic Enum to List<T> converter (C#) - Expanding the .NET blogosphere
interesting work and discussion

public static List EnumToList()

{

Type enumType = typeof(T);

// Can't use type constraints on value types, so have to do check like this

if (enumType.BaseType != typeof(Enum))

throw new ArgumentException("T must be of type System.Enum");

return new List(Enum.GetValues(enumType) as IEnumerable);

}

没有评论:

发表评论