Merge ifs into following switch on same expression in ReadAsBytes (#1147)

This commit is contained in:
Jon Hanna
2017-01-09 14:01:18 +13:00
committed by James Newton-King
parent 859d12e338
commit ec2659e3ad
+16 -21
View File
@@ -510,29 +510,23 @@ namespace Newtonsoft.Json
{
JsonToken t = GetContentToken();
if (t == JsonToken.None)
{
return null;
}
if (TokenType == JsonToken.StartObject)
{
ReadIntoWrappedTypeObject();
byte[] data = ReadAsBytes();
ReaderReadAndAssert();
if (TokenType != JsonToken.EndObject)
{
throw JsonReaderException.Create(this, "Error reading bytes. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType));
}
SetToken(JsonToken.Bytes, data, false);
return data;
}
switch (t)
{
case JsonToken.StartObject:
{
ReadIntoWrappedTypeObject();
byte[] data = ReadAsBytes();
ReaderReadAndAssert();
if (TokenType != JsonToken.EndObject)
{
throw JsonReaderException.Create(this, "Error reading bytes. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType));
}
SetToken(JsonToken.Bytes, data, false);
return data;
}
case JsonToken.String:
{
// attempt to convert possible base 64 or GUID string to bytes
@@ -558,6 +552,7 @@ namespace Newtonsoft.Json
SetToken(JsonToken.Bytes, data, false);
return data;
}
case JsonToken.None:
case JsonToken.Null:
case JsonToken.EndArray:
return null;