Ejemplo n.º 1
0
        private static IValue ConvertEnum(object objParam, Type type)
        {
            if (!type.IsAssignableFrom(objParam.GetType()))
            {
                throw new RuntimeException("Некорректный тип конвертируемого перечисления");
            }

            var memberInfo = type.GetMember(objParam.ToString());
            var valueInfo  = memberInfo.FirstOrDefault(x => x.DeclaringType == type);
            var attrs      = valueInfo.GetCustomAttributes(typeof(EnumItemAttribute), false);

            if (attrs.Length == 0)
            {
                throw new RuntimeException("Значение перечисления должно быть помечено атрибутом EnumItemAttribute");
            }

            var itemName = ((EnumItemAttribute)attrs[0]).Name;
            var enumImpl = GlobalsManager.GetSimpleEnum(type);

            return(enumImpl.GetPropValue(itemName));
        }