public static Dictionary <At2000Io, BinaryIoAttribute> GetSettings( IoType type) { try { return(Enum.GetValues(typeof(At2000Io)).Cast <At2000Io>().Select(x => { var data = new { Type = x, Settings = EnumAttributeCache <At2000Io> .GetCustomAttribute <BinaryIoAttribute>(x) }; return data; }).Where(x => x.Settings != null && x.Settings.IoIoType == type).GroupBy(x => x.Type, x => x.Settings).ToDictionary(x => x.Key, x => x.Single())); } catch (InvalidOperationException ex) { throw new ApplicationException(string.Format("The AT 2000 I/O configuration is not valid. There are duplicate I/O values."), ex); } }
public static TAttribute GetAttribute <TAttribute>(this Enum enumKey) where TAttribute : Attribute => EnumAttributeCache <TAttribute> .GetOrAdd(enumKey, _ => enumKey.GetAttributeCore <TAttribute>());