-Refactor
This commit is contained in:
@@ -66,7 +66,7 @@ namespace Newtonsoft.Json.Converters
|
||||
|
||||
private object ReadValue(JsonReader reader)
|
||||
{
|
||||
if (!reader.MoveToContentUnsafe())
|
||||
if (!reader.MoveToContent())
|
||||
{
|
||||
throw JsonSerializationException.Create(reader, "Unexpected end when reading ExpandoObject.");
|
||||
}
|
||||
|
||||
@@ -457,7 +457,7 @@ namespace Newtonsoft.Json
|
||||
{
|
||||
_readType = ReadType.ReadAsDateTimeOffset;
|
||||
|
||||
JsonToken t = ReadToContentInternal();
|
||||
JsonToken t = GetContentTokenInternal();
|
||||
|
||||
switch (t)
|
||||
{
|
||||
@@ -504,7 +504,7 @@ namespace Newtonsoft.Json
|
||||
{
|
||||
_readType = ReadType.ReadAsBytes;
|
||||
|
||||
JsonToken t = ReadToContentInternal();
|
||||
JsonToken t = GetContentTokenInternal();
|
||||
|
||||
if (t == JsonToken.None)
|
||||
{
|
||||
@@ -563,7 +563,7 @@ namespace Newtonsoft.Json
|
||||
|
||||
while (true)
|
||||
{
|
||||
switch (t = ReadToContentInternal())
|
||||
switch (t = GetContentTokenInternal())
|
||||
{
|
||||
case JsonToken.None:
|
||||
throw JsonReaderException.Create(this, "Unexpected end when reading bytes.");
|
||||
@@ -586,7 +586,7 @@ namespace Newtonsoft.Json
|
||||
{
|
||||
_readType = ReadType.ReadAsDecimal;
|
||||
|
||||
JsonToken t = ReadToContentInternal();
|
||||
JsonToken t = GetContentTokenInternal();
|
||||
|
||||
switch (t)
|
||||
{
|
||||
@@ -628,7 +628,7 @@ namespace Newtonsoft.Json
|
||||
{
|
||||
_readType = ReadType.ReadAsInt32;
|
||||
|
||||
switch (ReadToContentInternal())
|
||||
switch (GetContentTokenInternal())
|
||||
{
|
||||
case JsonToken.None:
|
||||
case JsonToken.Null:
|
||||
@@ -668,7 +668,7 @@ namespace Newtonsoft.Json
|
||||
{
|
||||
_readType = ReadType.ReadAsString;
|
||||
|
||||
JsonToken t = ReadToContentInternal();
|
||||
JsonToken t = GetContentTokenInternal();
|
||||
|
||||
switch (t)
|
||||
{
|
||||
@@ -706,7 +706,7 @@ namespace Newtonsoft.Json
|
||||
{
|
||||
_readType = ReadType.ReadAsDateTime;
|
||||
|
||||
switch (ReadToContentInternal())
|
||||
switch (GetContentTokenInternal())
|
||||
{
|
||||
case JsonToken.None:
|
||||
case JsonToken.Null:
|
||||
@@ -996,44 +996,28 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the next non-comment JSON token from the stream.
|
||||
/// </summary>
|
||||
/// <returns>true if the next non-comment token was read successfully; false if there are no more tokens to read.</returns>
|
||||
public bool ReadToContent()
|
||||
internal bool ReadAndMoveToContent()
|
||||
{
|
||||
return Read() && MoveToContentUnsafe();
|
||||
return Read() && MoveToContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the current JSON token is a content (non-comment) token, reading past comments if necessary.
|
||||
/// </summary>
|
||||
/// <returns>true if the current token was not a comment, or the reader successfully read to a non-comment token; false if there are no more tokens to read.</returns>
|
||||
public bool MoveToContent()
|
||||
internal bool MoveToContent()
|
||||
{
|
||||
if (TokenType == JsonToken.None && !Read())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return MoveToContentUnsafe();
|
||||
}
|
||||
|
||||
// MoveToContent() but assumes stream was already read into.
|
||||
internal bool MoveToContentUnsafe()
|
||||
{
|
||||
while (TokenType == JsonToken.Comment)
|
||||
JsonToken t = TokenType;
|
||||
while (t == JsonToken.None || t == JsonToken.Comment)
|
||||
{
|
||||
if (!Read())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
t = TokenType;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private JsonToken ReadToContentInternal()
|
||||
private JsonToken GetContentTokenInternal()
|
||||
{
|
||||
JsonToken t;
|
||||
do
|
||||
|
||||
@@ -132,7 +132,7 @@ namespace Newtonsoft.Json.Linq
|
||||
}
|
||||
}
|
||||
|
||||
reader.MoveToContentUnsafe();
|
||||
reader.MoveToContent();
|
||||
|
||||
if (reader.TokenType != JsonToken.StartArray)
|
||||
{
|
||||
|
||||
@@ -221,7 +221,7 @@ namespace Newtonsoft.Json.Linq
|
||||
}
|
||||
}
|
||||
|
||||
reader.MoveToContentUnsafe();
|
||||
reader.MoveToContent();
|
||||
|
||||
if (reader.TokenType != JsonToken.StartConstructor)
|
||||
{
|
||||
|
||||
@@ -370,7 +370,7 @@ namespace Newtonsoft.Json.Linq
|
||||
}
|
||||
}
|
||||
|
||||
reader.MoveToContentUnsafe();
|
||||
reader.MoveToContent();
|
||||
|
||||
if (reader.TokenType != JsonToken.StartObject)
|
||||
{
|
||||
|
||||
@@ -382,7 +382,7 @@ namespace Newtonsoft.Json.Linq
|
||||
}
|
||||
}
|
||||
|
||||
reader.MoveToContentUnsafe();
|
||||
reader.MoveToContent();
|
||||
|
||||
if (reader.TokenType != JsonToken.PropertyName)
|
||||
{
|
||||
|
||||
@@ -2113,7 +2113,11 @@ namespace Newtonsoft.Json.Linq
|
||||
|
||||
if (reader.TokenType == JsonToken.None)
|
||||
{
|
||||
if (!(settings != null && settings.CommentHandling == CommentHandling.Ignore ? reader.ReadToContent() : reader.Read()))
|
||||
bool hasContent = (settings != null && settings.CommentHandling == CommentHandling.Ignore)
|
||||
? reader.ReadAndMoveToContent()
|
||||
: reader.Read();
|
||||
|
||||
if (!hasContent)
|
||||
{
|
||||
throw JsonReaderException.Create(reader, "Error reading JToken from JsonReader.");
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ namespace Newtonsoft.Json.Serialization
|
||||
if (reader.TokenType == JsonToken.PropertyName)
|
||||
{
|
||||
string propertyName = (string)reader.Value;
|
||||
if (!reader.ReadToContent())
|
||||
if (!reader.ReadAndMoveToContent())
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -2195,7 +2195,7 @@ namespace Newtonsoft.Json.Serialization
|
||||
// the value might be a string which will then get converted which will error if read as date for example
|
||||
if (hasConverter)
|
||||
{
|
||||
return reader.ReadToContent();
|
||||
return reader.ReadAndMoveToContent();
|
||||
}
|
||||
|
||||
ReadType t = (contract != null) ? contract.InternalReadType : ReadType.Read;
|
||||
@@ -2203,7 +2203,7 @@ namespace Newtonsoft.Json.Serialization
|
||||
switch (t)
|
||||
{
|
||||
case ReadType.Read:
|
||||
return reader.ReadToContent();
|
||||
return reader.ReadAndMoveToContent();
|
||||
case ReadType.ReadAsInt32:
|
||||
reader.ReadAsInt32();
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user