using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace Wabbajack.Common { public static class EnumExt { public static IEnumerable GetValues() where T : struct, Enum { return Enum.GetValues(typeof(T)).Cast(); } public static string ToDescriptionString(this TEnum val) where TEnum : struct, IConvertible { if (!typeof(TEnum).IsEnum) { throw new ArgumentException("T must be an Enum"); } var attributes = (DescriptionAttribute[])val.GetType().GetField(val.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false); return attributes.Length > 0 ? attributes[0].Description : val.ToString(); } } }