Ejemplo n.º 1
0
            private Func <Type, string, ParseStep.Result> _CreateParseContext()
            {
                var _stack = new HashSet <ParseStep>();
                Func <Type, string, ParseStep.Result> _tryParse = null;

                _tryParse = (_type, _s) =>
                {
                    var _parseSteps = _GetParseSteps(_type);
                    if (_parseSteps.Length == 0)
                    {
                        return(StringParseResult.UnsupportedType(_type, _s));
                    }

                    foreach (var _parseStep in _parseSteps)
                    {
                        if (_stack.Add(_parseStep))
                        {
                            return(_parseStep.TryParse(_type, _s, _CultureInfo, _tryParse));
                        }
                    }

                    return(StringParseResult.InvalidString(_type, _s));
                };

                return(_tryParse);
            }
Ejemplo n.º 2
0
 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));
     }
 }
Ejemplo n.º 3
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();
            }