Ejemplo n.º 1
0
        public T Parse <T>(bool ignoreCase = true) where T : struct
        {
            var result = (T)Enum.Parse(typeof(T), _input, ignoreCase);

            EnumTools.ValidateResult(typeof(T), result, _input);

            return(result);
        }
Ejemplo n.º 2
0
        public object ParseByType(Type enumType, bool ignoreCase = true)
        {
            var result = Enum.Parse(enumType, _input, ignoreCase);

            EnumTools.ValidateResult(enumType, result, _input);

            return(result);
        }
        public T Parse <T>(T defaultValue = default(T), bool ignoreCase = true) where T : struct
        {
            T result;

            if (!Enum.TryParse(_input, ignoreCase, out result))
            {
                return(defaultValue);
            }

            return(!EnumTools.ResultIsValid(typeof(T), result) ? defaultValue : result);
        }
        public T?Parse <T>(bool ignoreCase = true) where T : struct
        {
            T result;

            if (!Enum.TryParse(_input, ignoreCase, out result))
            {
                return(null);
            }
            if (!EnumTools.ResultIsValid(typeof(T), result))
            {
                return(null);
            }

            return(result);
        }
        public object ParseByType(Type enumType, object defaultValue = default(object), bool ignoreCase = true)
        {
            // TODO: Localize
            if (enumType == null)
            {
                throw new ArgumentNullException("enumType");
            }
            if (!enumType.IsEnum)
            {
                throw new ArgumentException("Type passed must be an enum.", "enumType");
            }

            try
            {
                var result = Enum.Parse(enumType, _input, ignoreCase);
                return(!EnumTools.ResultIsValid(enumType, result) ? defaultValue : result);
            }
            catch (Exception)
            {
                return(defaultValue);
            }
        }