Esempio n. 1
0
        private static Dictionary <string, UiInfoAttribute> SetBadgeList()
        {
            List <KeyValuePair <string, UiInfoAttribute> > list = new List <KeyValuePair <string, UiInfoAttribute> >();

            IEnumerable <BadgeType> badges = Enum.GetValues(typeof(BadgeType)).Cast <BadgeType>();

            badges.ToList().ForEach(x =>
            {
                UiInfoAttribute uiInfo = x.GetAttributeOfType <UiInfoAttribute>();

                list.Add(new KeyValuePair <string, UiInfoAttribute>(x.ToString(), uiInfo));
            });

            Dictionary <string, UiInfoAttribute> dict = list.OrderBy(x => x.Value.Order).ToDictionary(x => x.Key, x => x.Value);

            return(dict);
        }
Esempio n. 2
0
        public static UiInfoAttribute ToUiInfo <TEnum>(this TEnum enumeration) where TEnum : Enum
        {
            if (!typeof(TEnum).IsEnum)
            {
                throw new ArgumentException("Type must be an enum");
            }

            UiInfoAttribute uiInfo = enumeration.GetAttributeOfType <UiInfoAttribute>();

            if (uiInfo == null)
            {
                return(new UiInfoAttribute
                {
                    Display = enumeration.ToString()
                });
            }
            else
            {
                return(uiInfo);
            }
        }