public override StringParseResult <object> TryParse(Type type, string s)
 {
     try
     {
         return(StringParseResult.Valid(type, s, Convert.ChangeType(s, type, _CultureInfo)));
     }
     catch (InvalidCastException)
     {
         return(StringParseResult.UnsupportedType(type, s));
     }
     catch (FormatException)
     {
         return(StringParseResult.InvalidString(type, s));
     }
     catch (OverflowException)
     {
         return(StringParseResult.InvalidString(type, s));
     }
 }
示例#2
0
            public StringParseResult <object> ToStringParseResult(Type type, string s)
            {
                if (UnderlyingResult.HasValue)
                {
                    return(UnderlyingResult.Value);
                }

                if (IsTypeSupported.GetValueOrDefault() && IsStringValid.GetValueOrDefault())
                {
                    return(StringParseResult.Valid(type, s, Value));
                }

                if (!IsTypeSupported.GetValueOrDefault(true))
                {
                    return(StringParseResult.UnsupportedType(type, s));
                }

                if (!IsStringValid.GetValueOrDefault(true))
                {
                    return(StringParseResult.InvalidString(type, s));
                }

                throw new UnexpectedStringParseErrorException();
            }