Пример #1
0
        /// <summary>
        /// Returns a BsSelectList from enum using the DescriptionAttribute
        /// </summary>
        public static BsSelectList <T> FromEnum(Type myEnum)
        {
            var enumType = myEnum;

            if (!enumType.IsEnum)
            {
                throw new ArgumentException("E is not of type enum", "myEnum");
            }

            var bsList = new BsSelectList <T>();

            foreach (var item in Enum.GetValues(enumType))
            {
                //get Display Name from resources
                var textValue = ReflectionHelpers.EnumDisplayName(myEnum, item as Enum);

                bsList.Items.Add(new BsSelectListItem
                {
                    Selected = false,
                    Text     = textValue,
                    Value    = Convert.ChangeType(item, Enum.GetUnderlyingType(myEnum)).ToString()
                });
            }

            return(bsList);
        }
Пример #2
0
        /// <summary>
        /// Returns a BsSelectList from
        /// </summary>
        public static BsSelectList <T> FromSelectList(IEnumerable <SelectListItem> list)
        {
            var bsList = new BsSelectList <T>();

            foreach (var item in list)
            {
                bsList.Items.Add(new BsSelectListItem
                {
                    Selected = item.Selected,
                    Text     = item.Text,
                    Value    = item.Value
                });
            }
            return(bsList);
        }