0 Comments
enum Test
    {
        [Description("Testing A")] A,
        [Description("Testing B")] B,
        [Description("Testing C")] C
    }

    static class Extensions
    {
        public static string GetDescription(this Enum value)
        {
            var description = value.ToString();
            var attributes = (DescriptionAttribute[]) value.GetType().GetField(description).GetCustomAttributes(typeof(DescriptionAttribute), false);
            if (attributes.Length != 0) description = attributes[0].Description;
            return description;
        }
    }

Comments