Enum To Array
#region License // (c) Intergen. // This source is subject to the Microsoft Public License (Ms-PL). // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. // All other rights reserved. #endregion using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; namespace TextGlow.Control.Utilities { public static class EnumUtils { public static void sdf() { } public static T[] EnumToArray<T>() where T : struct { //get the enumeration type Type et = typeof(T); T defaultValue = default(T); //get the public static fields (members of the enum) FieldInfo[] fi = et.GetFields(BindingFlags.Static | BindingFlags.Public); //create a new enum array T[] values = new T[fi.Length]; //populate with the values for (int i = 0; i < fi.Length; i++) { values[i] = (T)fi[i].GetValue(defaultValue); } //return the array return values; } } }