using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; namespace IRIGCh10 { public static class DescriptionDecoder { public static string GetDescription(Enum value) { var fi = value.GetType().GetField(value.ToString()); var attributes = (DescriptionAttribute[]) fi.GetCustomAttributes( typeof(DescriptionAttribute), false); if (attributes.Any()) { return attributes.First().Description; } return value.ToString(); } } public static class MaxLengthDecoder { public static int GetMaxLength(Enum value) { var fi = value.GetType().GetField(value.ToString()); var attributes = (MaxLengthAttribute[]) fi.GetCustomAttributes( typeof(MaxLengthAttribute), false); if (attributes.Any()) { return attributes.First().Length; } return 0; } } }