コード例 #1
0
        internal double GetDoubleWithQuotes()
        {
            ReadOnlySpan <byte> span = GetUnescapedSpan();

            if (JsonReaderHelper.TryGetFloatingPointConstant(span, out double value))
            {
                return(value);
            }

            char numberFormat = JsonReaderHelper.GetFloatingPointStandardParseFormat(span);

            if (Utf8Parser.TryParse(span, out value, out int bytesConsumed, numberFormat) &&
                span.Length == bytesConsumed)
            {
                // NETCOREAPP implmentation of the TryParse method above permits case-insenstive variants of the
                // float constants "NaN", "Infinity", "-Infinity". This differs from the NETFRAMEWORK implementation.
                // The following logic reconciles the two implementations to enforce consistent behavior.
                if (!double.IsNaN(value) && !double.IsPositiveInfinity(value) && !double.IsNegativeInfinity(value))
                {
                    return(value);
                }
            }

            throw ThrowHelper.GetFormatException(NumericType.Double);
        }
コード例 #2
0
        internal decimal GetDecimalWithQuotes()
        {
            ReadOnlySpan <byte> span = GetUnescapedSpan();

            char numberFormat = JsonReaderHelper.GetFloatingPointStandardParseFormat(span);

            if (Utf8Parser.TryParse(span, out decimal value, out int bytesConsumed, numberFormat) &&
                span.Length == bytesConsumed)
            {
                return(value);
            }

            throw ThrowHelper.GetFormatException(NumericType.Decimal);
        }