using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CurrencyAlert { public static class EnumHelper { /// /// Gets an attribute on an enum field value /// /// The type of the attribute you want to retrieve /// The enum value /// The attribute of type T that exists on the enum value /// ().Description;]]> public static T GetAttributeOfType(this System.Enum enumVal) where T : System.Attribute { var type = enumVal.GetType(); var memInfo = type.GetMember(enumVal.ToString()); var attributes = memInfo[0].GetCustomAttributes(typeof(T), false); return (attributes.Length > 0) ? (T)attributes[0] : null; } public static void Each(Action action) { foreach (var item in System.Enum.GetValues(typeof(T))) action((T)item); } } }