Async JToken methods
This commit is contained in:
committed by
James Newton-King
parent
dde1d905df
commit
c9b2ec8055
@@ -26,7 +26,6 @@
|
||||
#if !(NET20 || NET35 || NET40 || PORTABLE40)
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
#if !PORTABLE || NETSTANDARD1_1
|
||||
@@ -699,6 +698,30 @@ namespace Newtonsoft.Json
|
||||
&& await reader.ReadAsync(cancellationToken).ConfigureAwait(false));
|
||||
}
|
||||
|
||||
// For internal use, when we know the writer does not offer true async support (e.g. when backed
|
||||
// by a StringWriter) and therefore async write methods are always in practice just a less efficient
|
||||
// path through the sync version.
|
||||
internal async Task WriteTokenSyncReadingAsync(JsonReader reader, CancellationToken cancellationToken)
|
||||
{
|
||||
int initialDepth = CalculateWriteTokenDepth(reader);
|
||||
|
||||
do
|
||||
{
|
||||
// write a JValue date when the constructor is for a date
|
||||
if (reader.TokenType == JsonToken.StartConstructor && string.Equals(reader.Value.ToString(), "Date", StringComparison.Ordinal))
|
||||
{
|
||||
WriteConstructorDate(reader);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteToken(reader.TokenType, reader.Value);
|
||||
}
|
||||
} while (
|
||||
// stop if we have reached the end of the token being read
|
||||
initialDepth - 1 < reader.Depth - (JsonTokenUtils.IsEndToken(reader.TokenType) ? 1 : 0)
|
||||
&& await reader.ReadAsync(cancellationToken).ConfigureAwait(false));
|
||||
}
|
||||
|
||||
private async Task WriteConstructorDateAsync(JsonReader reader, CancellationToken cancellationToken)
|
||||
{
|
||||
if (!await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
|
||||
|
||||
Reference in New Issue
Block a user