using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace ENI2.Util { public static class EnumHelper { public static string Description (this Enum eValue) { var nAttributes = eValue.GetType().GetField(eValue.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false); if (nAttributes.Any()) return (nAttributes.First() as DescriptionAttribute).Description; return eValue.ToString(); } public static IEnumerable> GetAllValuesAndDescription(Type t) { if (!t.IsEnum) throw new ArgumentException("t must be an enum"); return from e in Enum.GetValues(t).Cast() select new KeyValuePair(e.ToString(), e.Description()); } } }