-Minor refactor
This commit is contained in:
@@ -202,8 +202,7 @@ namespace Newtonsoft.Json
|
|||||||
|
|
||||||
if (dateParseHandling == DateParseHandling.DateTime)
|
if (dateParseHandling == DateParseHandling.DateTime)
|
||||||
{
|
{
|
||||||
DateTime dt;
|
if (DateTimeUtils.TryParseDateTime(_stringReference, DateTimeZoneHandling, DateFormatString, Culture, out DateTime dt))
|
||||||
if (DateTimeUtils.TryParseDateTime(_stringReference, DateTimeZoneHandling, DateFormatString, Culture, out dt))
|
|
||||||
{
|
{
|
||||||
SetToken(JsonToken.Date, dt, false);
|
SetToken(JsonToken.Date, dt, false);
|
||||||
return;
|
return;
|
||||||
@@ -212,8 +211,7 @@ namespace Newtonsoft.Json
|
|||||||
#if HAVE_DATE_TIME_OFFSET
|
#if HAVE_DATE_TIME_OFFSET
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DateTimeOffset dt;
|
if (DateTimeUtils.TryParseDateTimeOffset(_stringReference, DateFormatString, Culture, out DateTimeOffset dt))
|
||||||
if (DateTimeUtils.TryParseDateTimeOffset(_stringReference, DateFormatString, Culture, out dt))
|
|
||||||
{
|
{
|
||||||
SetToken(JsonToken.Date, dt, false);
|
SetToken(JsonToken.Date, dt, false);
|
||||||
return;
|
return;
|
||||||
@@ -709,17 +707,17 @@ namespace Newtonsoft.Json
|
|||||||
case ReadType.ReadAsString:
|
case ReadType.ReadAsString:
|
||||||
return Value;
|
return Value;
|
||||||
case ReadType.ReadAsDateTime:
|
case ReadType.ReadAsDateTime:
|
||||||
if (Value is DateTime)
|
if (Value is DateTime time)
|
||||||
{
|
{
|
||||||
return (DateTime)Value;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ReadDateTimeString((string)Value);
|
return ReadDateTimeString((string)Value);
|
||||||
#if HAVE_DATE_TIME_OFFSET
|
#if HAVE_DATE_TIME_OFFSET
|
||||||
case ReadType.ReadAsDateTimeOffset:
|
case ReadType.ReadAsDateTimeOffset:
|
||||||
if (Value is DateTimeOffset)
|
if (Value is DateTimeOffset offset)
|
||||||
{
|
{
|
||||||
return (DateTimeOffset)Value;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ReadDateTimeOffsetString((string)Value);
|
return ReadDateTimeOffsetString((string)Value);
|
||||||
@@ -791,9 +789,9 @@ namespace Newtonsoft.Json
|
|||||||
ParseNumber(ReadType.Read);
|
ParseNumber(ReadType.Read);
|
||||||
bool b;
|
bool b;
|
||||||
#if HAVE_BIG_INTEGER
|
#if HAVE_BIG_INTEGER
|
||||||
if (Value is BigInteger)
|
if (Value is BigInteger integer)
|
||||||
{
|
{
|
||||||
b = (BigInteger)Value != 0;
|
b = integer != 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
@@ -1286,8 +1284,7 @@ namespace Newtonsoft.Json
|
|||||||
{
|
{
|
||||||
if (enoughChars)
|
if (enoughChars)
|
||||||
{
|
{
|
||||||
int value;
|
if (ConvertUtils.TryHexTextToInt(_chars, _charPos, _charPos + 4, out int value))
|
||||||
if (ConvertUtils.TryHexTextToInt(_chars, _charPos, _charPos + 4, out value))
|
|
||||||
{
|
{
|
||||||
char hexChar = Convert.ToChar(value);
|
char hexChar = Convert.ToChar(value);
|
||||||
_charPos += 4;
|
_charPos += 4;
|
||||||
@@ -1984,8 +1981,7 @@ namespace Newtonsoft.Json
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int value;
|
ParseResult parseResult = ConvertUtils.Int32TryParse(_stringReference.Chars, _stringReference.StartIndex, _stringReference.Length, out int value);
|
||||||
ParseResult parseResult = ConvertUtils.Int32TryParse(_stringReference.Chars, _stringReference.StartIndex, _stringReference.Length, out value);
|
|
||||||
if (parseResult == ParseResult.Success)
|
if (parseResult == ParseResult.Success)
|
||||||
{
|
{
|
||||||
numberValue = value;
|
numberValue = value;
|
||||||
@@ -2027,8 +2023,7 @@ namespace Newtonsoft.Json
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
decimal value;
|
ParseResult parseResult = ConvertUtils.DecimalTryParse(_stringReference.Chars, _stringReference.StartIndex, _stringReference.Length, out decimal value);
|
||||||
ParseResult parseResult = ConvertUtils.DecimalTryParse(_stringReference.Chars, _stringReference.StartIndex, _stringReference.Length, out value);
|
|
||||||
if (parseResult == ParseResult.Success)
|
if (parseResult == ParseResult.Success)
|
||||||
{
|
{
|
||||||
numberValue = value;
|
numberValue = value;
|
||||||
@@ -2068,8 +2063,7 @@ namespace Newtonsoft.Json
|
|||||||
{
|
{
|
||||||
string number = _stringReference.ToString();
|
string number = _stringReference.ToString();
|
||||||
|
|
||||||
double value;
|
if (double.TryParse(number, NumberStyles.Float, CultureInfo.InvariantCulture, out double value))
|
||||||
if (double.TryParse(number, NumberStyles.Float, CultureInfo.InvariantCulture, out value))
|
|
||||||
{
|
{
|
||||||
numberValue = value;
|
numberValue = value;
|
||||||
}
|
}
|
||||||
@@ -2106,8 +2100,7 @@ namespace Newtonsoft.Json
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
long value;
|
ParseResult parseResult = ConvertUtils.Int64TryParse(_stringReference.Chars, _stringReference.StartIndex, _stringReference.Length, out long value);
|
||||||
ParseResult parseResult = ConvertUtils.Int64TryParse(_stringReference.Chars, _stringReference.StartIndex, _stringReference.Length, out value);
|
|
||||||
if (parseResult == ParseResult.Success)
|
if (parseResult == ParseResult.Success)
|
||||||
{
|
{
|
||||||
numberValue = value;
|
numberValue = value;
|
||||||
@@ -2133,8 +2126,7 @@ namespace Newtonsoft.Json
|
|||||||
{
|
{
|
||||||
if (_floatParseHandling == FloatParseHandling.Decimal)
|
if (_floatParseHandling == FloatParseHandling.Decimal)
|
||||||
{
|
{
|
||||||
decimal d;
|
parseResult = ConvertUtils.DecimalTryParse(_stringReference.Chars, _stringReference.StartIndex, _stringReference.Length, out decimal d);
|
||||||
parseResult = ConvertUtils.DecimalTryParse(_stringReference.Chars, _stringReference.StartIndex, _stringReference.Length, out d);
|
|
||||||
if (parseResult == ParseResult.Success)
|
if (parseResult == ParseResult.Success)
|
||||||
{
|
{
|
||||||
numberValue = d;
|
numberValue = d;
|
||||||
@@ -2148,8 +2140,7 @@ namespace Newtonsoft.Json
|
|||||||
{
|
{
|
||||||
string number = _stringReference.ToString();
|
string number = _stringReference.ToString();
|
||||||
|
|
||||||
double d;
|
if (double.TryParse(number, NumberStyles.Float, CultureInfo.InvariantCulture, out double d))
|
||||||
if (double.TryParse(number, NumberStyles.Float, CultureInfo.InvariantCulture, out d))
|
|
||||||
{
|
{
|
||||||
numberValue = d;
|
numberValue = d;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -962,9 +962,9 @@ namespace Newtonsoft.Json
|
|||||||
return WriteNullAsync(cancellationToken);
|
return WriteNullAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
#if HAVE_BIG_INTEGER
|
#if HAVE_BIG_INTEGER
|
||||||
if (value is BigInteger)
|
if (value is BigInteger i)
|
||||||
{
|
{
|
||||||
return WriteValueAsync((BigInteger)value, cancellationToken);
|
return WriteValueAsync(i, cancellationToken);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1354,6 +1354,4 @@ namespace Newtonsoft.Json
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -546,9 +546,9 @@ namespace Newtonsoft.Json
|
|||||||
case JsonToken.Integer:
|
case JsonToken.Integer:
|
||||||
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||||
#if HAVE_BIG_INTEGER
|
#if HAVE_BIG_INTEGER
|
||||||
if (value is BigInteger)
|
if (value is BigInteger integer)
|
||||||
{
|
{
|
||||||
WriteValue((BigInteger)value);
|
WriteValue(integer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
@@ -558,9 +558,9 @@ namespace Newtonsoft.Json
|
|||||||
break;
|
break;
|
||||||
case JsonToken.Float:
|
case JsonToken.Float:
|
||||||
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||||
if (value is decimal)
|
if (value is decimal d)
|
||||||
{
|
{
|
||||||
WriteValue((decimal)value);
|
WriteValue(d);
|
||||||
}
|
}
|
||||||
else if (value is double)
|
else if (value is double)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user