コード例 #1
0
ファイル: PickerItem.cs プロジェクト: bmacombe/soltechxf
        public static PickerItem <T> GetPickerItemFromEnum(T item, ILocalizer localizer, String resourceNamespace)
        {
            if (localizer == null)
            {
                throw new ArgumentNullException("localizer");
            }
            if (String.IsNullOrEmpty(resourceNamespace))
            {
                throw new ArgumentNullException("resourceNamespace");
            }

            Type enumType = typeof(T);

            if (!enumType.GetTypeInfo().IsEnum)
            {
                throw new ArgumentException("You must provide an enumeration.", "enumeration");
            }

            if (!Enum.IsDefined(enumType, item))
            {
                throw new ArgumentOutOfRangeException("item");
            }

            var entry       = enumType.GetRuntimeField(Enum.GetName(enumType, item));
            var description = entry.GetCustomAttribute <DescriptionAttribute>();
            var pickerEntry = new PickerItem <T>(localizer.GetText(resourceNamespace, enumType.Name, description.ResourceId), (T)entry.GetValue(null));

            return(pickerEntry);
        }
コード例 #2
0
ファイル: PickerItem.cs プロジェクト: bmacombe/soltechxf
        public static IList <PickerItem <T> > GetPickerItemListFromEnum()
        {
            Type enumType = typeof(T);

            if (!enumType.GetTypeInfo().IsEnum)
            {
                throw new ArgumentException("You must provide an enumeration.", "enumeration");
            }

            var list = new List <PickerItem <T> >();

            foreach (var entryName in Enum.GetNames(enumType))
            {
                var            entry       = enumType.GetRuntimeField(entryName);
                var            description = entry.GetCustomAttribute <DescriptionAttribute>();
                PickerItem <T> pickerEntry;
                if (description != default(DescriptionAttribute))
                {
                    pickerEntry = new PickerItem <T>(description.Description, (T)entry.GetValue(null));
                }
                else
                {
                    pickerEntry = new PickerItem <T>(enumType.Name, (T)entry.GetValue(null));
                }
                list.Add(pickerEntry);
            }

            return(list);
        }
コード例 #3
0
ファイル: PickerItem.cs プロジェクト: bmacombe/soltechxf
        public static IList <PickerItem <T> > GetPickerItemListFromEnum(ILocalizer localizer, String resourceNamespace)
        {
            if (localizer == null)
            {
                throw new ArgumentNullException("localizer");
            }
            if (String.IsNullOrEmpty(resourceNamespace))
            {
                throw new ArgumentNullException("resourceNamespace");
            }

            Type enumType = typeof(T);

            if (!enumType.GetTypeInfo().IsEnum)
            {
                throw new ArgumentException("You must provide an enumeration.", "enumeration");
            }

            var list = new List <PickerItem <T> >();

            foreach (var entryName in Enum.GetNames(enumType))
            {
                var entry       = enumType.GetRuntimeField(entryName);
                var description = entry.GetCustomAttribute <DescriptionAttribute>();
                var pickerEntry = new PickerItem <T>(localizer.GetText(resourceNamespace, enumType.Name, description.ResourceId), (T)entry.GetValue(null));
                list.Add(pickerEntry);
            }

            return(list);
        }
コード例 #4
0
ファイル: PickerItem.cs プロジェクト: bmacombe/soltechxf
        public static PickerItem <T> GetPickerItemFromEnum(T item)
        {
            Type enumType = typeof(T);

            if (!enumType.GetTypeInfo().IsEnum)
            {
                throw new ArgumentException("You must provide an enumeration.", "enumeration");
            }

            if (!Enum.IsDefined(enumType, item))
            {
                throw new ArgumentOutOfRangeException("item");
            }

            var            entry       = enumType.GetRuntimeField(Enum.GetName(enumType, item));
            var            description = entry.GetCustomAttribute <DescriptionAttribute>();
            PickerItem <T> pickerEntry;

            if (description != default(DescriptionAttribute))
            {
                pickerEntry = new PickerItem <T>(description.Description, (T)entry.GetValue(null));
            }
            else
            {
                pickerEntry = new PickerItem <T>(enumType.Name, (T)entry.GetValue(null));
            }


            return(pickerEntry);
        }
コード例 #5
0
ファイル: PickerItem.cs プロジェクト: bmacombe/soltechxf
        public override bool Equals(object obj)
        {
            PickerItem <T> other = obj as PickerItem <T>;

            if (other == null)
            {
                return(false);
            }

            return
                (String.Compare(Name, other.Name, StringComparison.CurrentCulture) == 0 &&
                 Item.Equals(other.Item));
        }
コード例 #6
0
ファイル: PickerItem.cs プロジェクト: bmacombe/soltechxf
        public static IEnumerable <PickerItem <T> > GetPickerItemList(IEnumerable <T> items)
        {
            var list = new List <PickerItem <T> >();

            if (items != null)
            {
                foreach (var item in items)
                {
                    var pickerEntry = new PickerItem <T> (item.ToString(), item);
                    list.Add(pickerEntry);
                }
            }

            return(list);
        }