Exemplo n.º 1
0
        public StringParseException Throw()
        {
            if (IsValid)
            {
                throw new InvalidOperationException($"{nameof(StringParseResult)}<>.{nameof(Throw)} may only be used on invalid results.");
            }

            if (!IsTypeSupported.GetValueOrDefault(true))
            {
                throw new StringParseTypeNotSupportedException(ParseType);
            }

            if (!IsStringValid.GetValueOrDefault(true))
            {
                throw new StringParseInvalidStringException(ParseType, String);
            }

            throw new UnexpectedStringParseErrorException();
        }
Exemplo n.º 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();
            }