using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel; /* Created: Michael Albert info@michlstechblog.info License: public */ namespace info.michlstechblog.readenumdescription { class Program { public enum MetalBands { [DescriptionAttribute("This is Metallica from CA")] Metallica, [DescriptionAttribute("This is Slayer from CA")] Slayer, [DescriptionAttribute("This is Overkill from NY")] Overkill }; public static string GetDescription(MetalBands Band) { System.Reflection.FieldInfo oFieldInfo = Band.GetType().GetField(Band.ToString()); DescriptionAttribute[] attributes = (DescriptionAttribute[])oFieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false); if (attributes.Length > 0) { return attributes[0].Description; } else { return Band.ToString(); } } static void Main(string[] args) { System.Reflection.FieldInfo oFieldInfo=MetalBands.Metallica.GetType().GetField(MetalBands.Metallica.ToString()); DescriptionAttribute[] attributes = (DescriptionAttribute[])oFieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false); if (attributes.Length > 0) { System.Console.WriteLine(attributes[0].Description); } System.Console.WriteLine(GetDescription(MetalBands.Metallica)); } } }