public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var type = parameter as Type;
            var vs   = Enum.GetValues(type);

            EnumItem[] items = new EnumItem[vs.Length];
            for (int i = 0; i < vs.Length; i++)

            {
                items[i].Value   = vs.GetValue(i);
                items[i].Display = (items[i].Value as Enum).GetDescription();
            }
            return(items);
        }
        public object Convert(object value, Type targetType = null, object parameter = null, CultureInfo culture = null)
        {
            if (value == null)
            {
                EnumTypeToItemSourceConverter converter = new EnumTypeToItemSourceConverter();
                return(converter.Convert(value, targetType, parameter, culture));
            }
            var vs    = (IList)value;
            var items = new EnumItem[vs.Count];

            for (int i = 0; i < vs.Count; i++)
            {
                items[i].Value   = vs[i];
                items[i].Display = (items[i].Value as Enum).GetDescription();
            }
            return(items);
        }
Esempio n. 3
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (this.Type == null || !this.Type.IsEnum)
            {
                throw new ArgumentNullException("enumType", "The argument[enumType] is invalid");
            }
            return(Util.Cache.CacheManager.GetCache <EnumItem[]>("EnumItems_Cache_" + Type.FullName, Util.Cache.CacheTime.Time_30min, () =>
            {
                var vs = Enum.GetValues(Type);

                EnumItem[] items = new EnumItem[vs.Length];
                for (int i = 0; i < vs.Length; i++)
                {
                    items[i].Value = vs.GetValue(i);
                    items[i].Display = (items[i].Value as Enum).GetDescription();
                }
                return items;
            }));
        }