Refactor to use new C# language features (#1881)

* Use shorter default syntax
* Inline out variable declarations
* Pattern matching
This commit is contained in:
James Newton-King
2018-10-15 12:49:25 +13:00
committed by GitHub
parent 0c6b0748f8
commit 0ce23ff924
51 changed files with 340 additions and 416 deletions
+1 -2
View File
@@ -135,9 +135,8 @@ namespace Newtonsoft.Json.Bson
long ticks = 0;
if (value.Value is DateTime)
if (value.Value is DateTime dateTime)
{
DateTime dateTime = (DateTime)value.Value;
if (DateTimeKindHandling == DateTimeKind.Utc)
{
dateTime = dateTime.ToUniversalTime();
+3 -4
View File
@@ -205,8 +205,7 @@ namespace Newtonsoft.Json.Bson
{
if (_parent != null)
{
BsonObject bo = _parent as BsonObject;
if (bo != null)
if (_parent is BsonObject bo)
{
bo.Add(_propertyName, token);
_propertyName = null;
@@ -237,10 +236,10 @@ namespace Newtonsoft.Json.Bson
public override void WriteValue(object value)
{
#if HAVE_BIG_INTEGER
if (value is BigInteger)
if (value is BigInteger i)
{
SetWriteState(JsonToken.Integer, null);
AddToken(new BsonBinary(((BigInteger)value).ToByteArray(), BsonBinaryType.Binary));
AddToken(new BsonBinary(i.ToByteArray(), BsonBinaryType.Binary));
}
else
#endif
@@ -158,10 +158,7 @@ namespace Newtonsoft.Json.Converters
/// <value>
/// <c>true</c> if this <see cref="JsonConverter"/> can write JSON; otherwise, <c>false</c>.
/// </value>
public override bool CanWrite
{
get { return false; }
}
public override bool CanWrite => false;
}
}
@@ -168,7 +168,7 @@ namespace Newtonsoft.Json.Converters
}
catch (Exception ex)
{
throw JsonSerializationException.Create(reader, "Error converting value {0} to type '{1}'.".FormatWith(CultureInfo.InvariantCulture, MiscellaneousUtils.FormatValueForPrint(reader.Value), objectType), ex);
throw JsonSerializationException.Create(reader, "Error converting value {0} to type '{1}'.".FormatWith(CultureInfo.InvariantCulture, MiscellaneousUtils.ToString(reader.Value), objectType), ex);
}
// we don't actually expect to get here.
@@ -125,7 +125,7 @@ namespace Newtonsoft.Json
/// </value>
public bool IsReference
{
get => _isReference ?? default(bool);
get => _isReference ?? default;
set => _isReference = value;
}
@@ -137,7 +137,7 @@ namespace Newtonsoft.Json
/// </value>
public bool ItemIsReference
{
get => _itemIsReference ?? default(bool);
get => _itemIsReference ?? default;
set => _itemIsReference = value;
}
@@ -147,7 +147,7 @@ namespace Newtonsoft.Json
/// <value>The reference loop handling.</value>
public ReferenceLoopHandling ItemReferenceLoopHandling
{
get => _itemReferenceLoopHandling ?? default(ReferenceLoopHandling);
get => _itemReferenceLoopHandling ?? default;
set => _itemReferenceLoopHandling = value;
}
@@ -157,7 +157,7 @@ namespace Newtonsoft.Json
/// <value>The type name handling.</value>
public TypeNameHandling ItemTypeNameHandling
{
get => _itemTypeNameHandling ?? default(TypeNameHandling);
get => _itemTypeNameHandling ?? default;
set => _itemTypeNameHandling = value;
}
+1 -1
View File
@@ -118,7 +118,7 @@ namespace Newtonsoft.Json
{
throw new JsonSerializationException("Converter cannot read JSON with the specified existing value. {0} is required.".FormatWith(CultureInfo.InvariantCulture, typeof(T)));
}
return ReadJson(reader, objectType, existingIsNull ? default(T) : (T)existingValue, !existingIsNull, serializer);
return ReadJson(reader, objectType, existingIsNull ? default : (T)existingValue, !existingIsNull, serializer);
}
/// <summary>
+2 -2
View File
@@ -56,7 +56,7 @@ namespace Newtonsoft.Json
/// <value>How the object's properties with null values are handled during serialization and deserialization.</value>
public NullValueHandling ItemNullValueHandling
{
get => _itemNullValueHandling ?? default(NullValueHandling);
get => _itemNullValueHandling ?? default;
set => _itemNullValueHandling = value;
}
@@ -68,7 +68,7 @@ namespace Newtonsoft.Json
/// </value>
public Required ItemRequired
{
get => _itemRequired ?? default(Required);
get => _itemRequired ?? default;
set => _itemRequired = value;
}
+10 -10
View File
@@ -92,7 +92,7 @@ namespace Newtonsoft.Json
/// <value>The null value handling.</value>
public NullValueHandling NullValueHandling
{
get => _nullValueHandling ?? default(NullValueHandling);
get => _nullValueHandling ?? default;
set => _nullValueHandling = value;
}
@@ -102,7 +102,7 @@ namespace Newtonsoft.Json
/// <value>The default value handling.</value>
public DefaultValueHandling DefaultValueHandling
{
get => _defaultValueHandling ?? default(DefaultValueHandling);
get => _defaultValueHandling ?? default;
set => _defaultValueHandling = value;
}
@@ -112,7 +112,7 @@ namespace Newtonsoft.Json
/// <value>The reference loop handling.</value>
public ReferenceLoopHandling ReferenceLoopHandling
{
get => _referenceLoopHandling ?? default(ReferenceLoopHandling);
get => _referenceLoopHandling ?? default;
set => _referenceLoopHandling = value;
}
@@ -122,7 +122,7 @@ namespace Newtonsoft.Json
/// <value>The object creation handling.</value>
public ObjectCreationHandling ObjectCreationHandling
{
get => _objectCreationHandling ?? default(ObjectCreationHandling);
get => _objectCreationHandling ?? default;
set => _objectCreationHandling = value;
}
@@ -132,7 +132,7 @@ namespace Newtonsoft.Json
/// <value>The type name handling.</value>
public TypeNameHandling TypeNameHandling
{
get => _typeNameHandling ?? default(TypeNameHandling);
get => _typeNameHandling ?? default;
set => _typeNameHandling = value;
}
@@ -142,7 +142,7 @@ namespace Newtonsoft.Json
/// <value>Whether this property's value is serialized as a reference.</value>
public bool IsReference
{
get => _isReference ?? default(bool);
get => _isReference ?? default;
set => _isReference = value;
}
@@ -152,7 +152,7 @@ namespace Newtonsoft.Json
/// <value>The numeric order of serialization.</value>
public int Order
{
get => _order ?? default(int);
get => _order ?? default;
set => _order = value;
}
@@ -180,7 +180,7 @@ namespace Newtonsoft.Json
/// <value>The collection's items reference loop handling.</value>
public ReferenceLoopHandling ItemReferenceLoopHandling
{
get => _itemReferenceLoopHandling ?? default(ReferenceLoopHandling);
get => _itemReferenceLoopHandling ?? default;
set => _itemReferenceLoopHandling = value;
}
@@ -190,7 +190,7 @@ namespace Newtonsoft.Json
/// <value>The collection's items type name handling.</value>
public TypeNameHandling ItemTypeNameHandling
{
get => _itemTypeNameHandling ?? default(TypeNameHandling);
get => _itemTypeNameHandling ?? default;
set => _itemTypeNameHandling = value;
}
@@ -200,7 +200,7 @@ namespace Newtonsoft.Json
/// <value>Whether this property's collection items are serialized as a reference.</value>
public bool ItemIsReference
{
get => _itemIsReference ?? default(bool);
get => _itemIsReference ?? default;
set => _itemIsReference = value;
}
+10 -10
View File
@@ -43,7 +43,7 @@ namespace Newtonsoft.Json
/// property returns <c>true</c> if the next token was read successfully; <c>false</c> if there are no more tokens to read.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task<bool> ReadAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<bool> ReadAsync(CancellationToken cancellationToken = default)
{
return cancellationToken.CancelIfRequestedAsync<bool>() ?? Read().ToAsync();
}
@@ -55,7 +55,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public async Task SkipAsync(CancellationToken cancellationToken = default(CancellationToken))
public async Task SkipAsync(CancellationToken cancellationToken = default)
{
if (TokenType == JsonToken.PropertyName)
{
@@ -88,7 +88,7 @@ namespace Newtonsoft.Json
/// property returns the <see cref="Nullable{T}"/> of <see cref="bool"/>. This result will be <c>null</c> at the end of an array.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task<bool?> ReadAsBooleanAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<bool?> ReadAsBooleanAsync(CancellationToken cancellationToken = default)
{
return cancellationToken.CancelIfRequestedAsync<bool?>() ?? Task.FromResult(ReadAsBoolean());
}
@@ -101,7 +101,7 @@ namespace Newtonsoft.Json
/// property returns the <see cref="byte"/>[]. This result will be <c>null</c> at the end of an array.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task<byte[]> ReadAsBytesAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<byte[]> ReadAsBytesAsync(CancellationToken cancellationToken = default)
{
return cancellationToken.CancelIfRequestedAsync<byte[]>() ?? Task.FromResult(ReadAsBytes());
}
@@ -134,7 +134,7 @@ namespace Newtonsoft.Json
/// property returns the <see cref="Nullable{T}"/> of <see cref="DateTime"/>. This result will be <c>null</c> at the end of an array.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task<DateTime?> ReadAsDateTimeAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<DateTime?> ReadAsDateTimeAsync(CancellationToken cancellationToken = default)
{
return cancellationToken.CancelIfRequestedAsync<DateTime?>() ?? Task.FromResult(ReadAsDateTime());
}
@@ -147,7 +147,7 @@ namespace Newtonsoft.Json
/// property returns the <see cref="Nullable{T}"/> of <see cref="DateTimeOffset"/>. This result will be <c>null</c> at the end of an array.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task<DateTimeOffset?> ReadAsDateTimeOffsetAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<DateTimeOffset?> ReadAsDateTimeOffsetAsync(CancellationToken cancellationToken = default)
{
return cancellationToken.CancelIfRequestedAsync<DateTimeOffset?>() ?? Task.FromResult(ReadAsDateTimeOffset());
}
@@ -160,7 +160,7 @@ namespace Newtonsoft.Json
/// property returns the <see cref="Nullable{T}"/> of <see cref="decimal"/>. This result will be <c>null</c> at the end of an array.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task<decimal?> ReadAsDecimalAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<decimal?> ReadAsDecimalAsync(CancellationToken cancellationToken = default)
{
return cancellationToken.CancelIfRequestedAsync<decimal?>() ?? Task.FromResult(ReadAsDecimal());
}
@@ -173,7 +173,7 @@ namespace Newtonsoft.Json
/// property returns the <see cref="Nullable{T}"/> of <see cref="double"/>. This result will be <c>null</c> at the end of an array.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task<double?> ReadAsDoubleAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<double?> ReadAsDoubleAsync(CancellationToken cancellationToken = default)
{
return Task.FromResult(ReadAsDouble());
}
@@ -186,7 +186,7 @@ namespace Newtonsoft.Json
/// property returns the <see cref="Nullable{T}"/> of <see cref="int"/>. This result will be <c>null</c> at the end of an array.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task<int?> ReadAsInt32Async(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<int?> ReadAsInt32Async(CancellationToken cancellationToken = default)
{
return cancellationToken.CancelIfRequestedAsync<int?>() ?? Task.FromResult(ReadAsInt32());
}
@@ -199,7 +199,7 @@ namespace Newtonsoft.Json
/// property returns the <see cref="string"/>. This result will be <c>null</c> at the end of an array.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task<string> ReadAsStringAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<string> ReadAsStringAsync(CancellationToken cancellationToken = default)
{
return cancellationToken.CancelIfRequestedAsync<string>() ?? Task.FromResult(ReadAsString());
}
+2 -4
View File
@@ -493,8 +493,7 @@ namespace Newtonsoft.Json
}
else
{
Uri uri = v as Uri;
s = uri != null ? uri.OriginalString : v.ToString();
s = v is Uri uri ? uri.OriginalString : v.ToString();
}
SetToken(JsonToken.String, s, false);
@@ -793,8 +792,7 @@ namespace Newtonsoft.Json
return null;
}
decimal d;
if (decimal.TryParse(s, NumberStyles.Number, Culture, out d))
if (decimal.TryParse(s, NumberStyles.Number, Culture, out decimal d))
{
SetToken(JsonToken.Float, d, false);
return d;
+16 -16
View File
@@ -812,14 +812,14 @@ namespace Newtonsoft.Json
ValidationUtils.ArgumentNotNull(reader, nameof(reader));
ValidationUtils.ArgumentNotNull(target, nameof(target));
// set serialization options onto reader
CultureInfo previousCulture;
DateTimeZoneHandling? previousDateTimeZoneHandling;
DateParseHandling? previousDateParseHandling;
FloatParseHandling? previousFloatParseHandling;
int? previousMaxDepth;
string previousDateFormatString;
SetupReader(reader, out previousCulture, out previousDateTimeZoneHandling, out previousDateParseHandling, out previousFloatParseHandling, out previousMaxDepth, out previousDateFormatString);
SetupReader(
reader,
out CultureInfo previousCulture,
out DateTimeZoneHandling? previousDateTimeZoneHandling,
out DateParseHandling? previousDateParseHandling,
out FloatParseHandling? previousFloatParseHandling,
out int? previousMaxDepth,
out string previousDateFormatString);
TraceJsonReader traceJsonReader = (TraceWriter != null && TraceWriter.LevelFilter >= TraceLevel.Verbose)
? CreateTraceJsonReader(reader)
@@ -890,14 +890,14 @@ namespace Newtonsoft.Json
{
ValidationUtils.ArgumentNotNull(reader, nameof(reader));
// set serialization options onto reader
CultureInfo previousCulture;
DateTimeZoneHandling? previousDateTimeZoneHandling;
DateParseHandling? previousDateParseHandling;
FloatParseHandling? previousFloatParseHandling;
int? previousMaxDepth;
string previousDateFormatString;
SetupReader(reader, out previousCulture, out previousDateTimeZoneHandling, out previousDateParseHandling, out previousFloatParseHandling, out previousMaxDepth, out previousDateFormatString);
SetupReader(
reader,
out CultureInfo previousCulture,
out DateTimeZoneHandling? previousDateTimeZoneHandling,
out DateParseHandling? previousDateParseHandling,
out FloatParseHandling? previousFloatParseHandling,
out int? previousMaxDepth,
out string previousDateFormatString);
TraceJsonReader traceJsonReader = (TraceWriter != null && TraceWriter.LevelFilter >= TraceLevel.Verbose)
? CreateTraceJsonReader(reader)
+11 -11
View File
@@ -53,7 +53,7 @@ namespace Newtonsoft.Json
/// property returns <c>true</c> if the next token was read successfully; <c>false</c> if there are no more tokens to read.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task<bool> ReadAsync(CancellationToken cancellationToken = default(CancellationToken))
public override Task<bool> ReadAsync(CancellationToken cancellationToken = default)
{
return _safeAsync ? DoReadAsync(cancellationToken) : base.ReadAsync(cancellationToken);
}
@@ -1387,7 +1387,7 @@ namespace Newtonsoft.Json
/// property returns the <see cref="Nullable{T}"/> of <see cref="bool"/>. This result will be <c>null</c> at the end of an array.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task<bool?> ReadAsBooleanAsync(CancellationToken cancellationToken = default(CancellationToken))
public override Task<bool?> ReadAsBooleanAsync(CancellationToken cancellationToken = default)
{
return _safeAsync ? DoReadAsBooleanAsync(cancellationToken) : base.ReadAsBooleanAsync(cancellationToken);
}
@@ -1446,9 +1446,9 @@ namespace Newtonsoft.Json
await ParseNumberAsync(ReadType.Read, cancellationToken).ConfigureAwait(false);
bool b;
#if HAVE_BIG_INTEGER
if (Value is BigInteger)
if (Value is BigInteger i)
{
b = (BigInteger)Value != 0;
b = i != 0;
}
else
#endif
@@ -1522,7 +1522,7 @@ namespace Newtonsoft.Json
/// property returns the <see cref="byte"/>[]. This result will be <c>null</c> at the end of an array.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task<byte[]> ReadAsBytesAsync(CancellationToken cancellationToken = default(CancellationToken))
public override Task<byte[]> ReadAsBytesAsync(CancellationToken cancellationToken = default)
{
return _safeAsync ? DoReadAsBytesAsync(cancellationToken) : base.ReadAsBytesAsync(cancellationToken);
}
@@ -1663,7 +1663,7 @@ namespace Newtonsoft.Json
/// property returns the <see cref="Nullable{T}"/> of <see cref="DateTime"/>. This result will be <c>null</c> at the end of an array.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task<DateTime?> ReadAsDateTimeAsync(CancellationToken cancellationToken = default(CancellationToken))
public override Task<DateTime?> ReadAsDateTimeAsync(CancellationToken cancellationToken = default)
{
return _safeAsync ? DoReadAsDateTimeAsync(cancellationToken) : base.ReadAsDateTimeAsync(cancellationToken);
}
@@ -1681,7 +1681,7 @@ namespace Newtonsoft.Json
/// property returns the <see cref="Nullable{T}"/> of <see cref="DateTimeOffset"/>. This result will be <c>null</c> at the end of an array.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task<DateTimeOffset?> ReadAsDateTimeOffsetAsync(CancellationToken cancellationToken = default(CancellationToken))
public override Task<DateTimeOffset?> ReadAsDateTimeOffsetAsync(CancellationToken cancellationToken = default)
{
return _safeAsync ? DoReadAsDateTimeOffsetAsync(cancellationToken) : base.ReadAsDateTimeOffsetAsync(cancellationToken);
}
@@ -1699,7 +1699,7 @@ namespace Newtonsoft.Json
/// property returns the <see cref="Nullable{T}"/> of <see cref="decimal"/>. This result will be <c>null</c> at the end of an array.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task<decimal?> ReadAsDecimalAsync(CancellationToken cancellationToken = default(CancellationToken))
public override Task<decimal?> ReadAsDecimalAsync(CancellationToken cancellationToken = default)
{
return _safeAsync ? DoReadAsDecimalAsync(cancellationToken) : base.ReadAsDecimalAsync(cancellationToken);
}
@@ -1717,7 +1717,7 @@ namespace Newtonsoft.Json
/// property returns the <see cref="Nullable{T}"/> of <see cref="double"/>. This result will be <c>null</c> at the end of an array.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task<double?> ReadAsDoubleAsync(CancellationToken cancellationToken = default(CancellationToken))
public override Task<double?> ReadAsDoubleAsync(CancellationToken cancellationToken = default)
{
return _safeAsync ? DoReadAsDoubleAsync(cancellationToken) : base.ReadAsDoubleAsync(cancellationToken);
}
@@ -1735,7 +1735,7 @@ namespace Newtonsoft.Json
/// property returns the <see cref="Nullable{T}"/> of <see cref="int"/>. This result will be <c>null</c> at the end of an array.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task<int?> ReadAsInt32Async(CancellationToken cancellationToken = default(CancellationToken))
public override Task<int?> ReadAsInt32Async(CancellationToken cancellationToken = default)
{
return _safeAsync ? DoReadAsInt32Async(cancellationToken) : base.ReadAsInt32Async(cancellationToken);
}
@@ -1753,7 +1753,7 @@ namespace Newtonsoft.Json
/// property returns the <see cref="string"/>. This result will be <c>null</c> at the end of an array.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task<string> ReadAsStringAsync(CancellationToken cancellationToken = default(CancellationToken))
public override Task<string> ReadAsStringAsync(CancellationToken cancellationToken = default)
{
return _safeAsync ? DoReadAsStringAsync(cancellationToken) : base.ReadAsStringAsync(cancellationToken);
}
+55 -55
View File
@@ -51,7 +51,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken))
public override Task FlushAsync(CancellationToken cancellationToken = default)
{
return _safeAsync ? DoFlushAsync(cancellationToken) : base.FlushAsync(cancellationToken);
}
@@ -114,7 +114,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task CloseAsync(CancellationToken cancellationToken = default(CancellationToken))
public override Task CloseAsync(CancellationToken cancellationToken = default)
{
return _safeAsync ? DoCloseAsync(cancellationToken) : base.CloseAsync(cancellationToken);
}
@@ -141,7 +141,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteEndAsync(CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteEndAsync(CancellationToken cancellationToken = default)
{
return _safeAsync ? WriteEndInternalAsync(cancellationToken) : base.WriteEndAsync(cancellationToken);
}
@@ -225,7 +225,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteRawAsync(string json, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteRawAsync(string json, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteRawAsync(json, cancellationToken) : base.WriteRawAsync(json, cancellationToken);
}
@@ -242,7 +242,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteNullAsync(CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteNullAsync(CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteNullAsync(cancellationToken) : base.WriteNullAsync(cancellationToken);
}
@@ -309,7 +309,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WritePropertyNameAsync(string name, CancellationToken cancellationToken = default(CancellationToken))
public override Task WritePropertyNameAsync(string name, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWritePropertyNameAsync(name, cancellationToken) : base.WritePropertyNameAsync(name, cancellationToken);
}
@@ -349,7 +349,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WritePropertyNameAsync(string name, bool escape, CancellationToken cancellationToken = default(CancellationToken))
public override Task WritePropertyNameAsync(string name, bool escape, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWritePropertyNameAsync(name, escape, cancellationToken) : base.WritePropertyNameAsync(name, escape, cancellationToken);
}
@@ -387,7 +387,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteStartArrayAsync(CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteStartArrayAsync(CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteStartArrayAsync(cancellationToken) : base.WriteStartArrayAsync(cancellationToken);
}
@@ -417,7 +417,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteStartObjectAsync(CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteStartObjectAsync(CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteStartObjectAsync(cancellationToken) : base.WriteStartObjectAsync(cancellationToken);
}
@@ -448,7 +448,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteStartConstructorAsync(string name, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteStartConstructorAsync(string name, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteStartConstructorAsync(name, cancellationToken) : base.WriteStartConstructorAsync(name, cancellationToken);
}
@@ -469,7 +469,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteUndefinedAsync(CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteUndefinedAsync(CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteUndefinedAsync(cancellationToken) : base.WriteUndefinedAsync(cancellationToken);
}
@@ -499,7 +499,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteWhitespaceAsync(string ws, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteWhitespaceAsync(string ws, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteWhitespaceAsync(ws, cancellationToken) : base.WriteWhitespaceAsync(ws, cancellationToken);
}
@@ -518,7 +518,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(bool value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(bool value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -536,7 +536,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(bool? value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(bool? value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -554,7 +554,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(byte value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(byte value, CancellationToken cancellationToken = default)
{
return _safeAsync ? WriteIntegerValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -567,7 +567,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(byte? value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(byte? value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -585,7 +585,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(byte[] value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(byte[] value, CancellationToken cancellationToken = default)
{
return _safeAsync ? (value == null ? WriteNullAsync(cancellationToken) : WriteValueNonNullAsync(value, cancellationToken)) : base.WriteValueAsync(value, cancellationToken);
}
@@ -607,7 +607,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(char value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(char value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -625,7 +625,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(char? value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(char? value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -643,7 +643,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(DateTime value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(DateTime value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -675,7 +675,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(DateTime? value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(DateTime? value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -693,7 +693,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(DateTimeOffset value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(DateTimeOffset value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -724,7 +724,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(DateTimeOffset? value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(DateTimeOffset? value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -742,7 +742,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(decimal value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(decimal value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -760,7 +760,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(decimal? value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(decimal? value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -778,7 +778,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(double value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(double value, CancellationToken cancellationToken = default)
{
return _safeAsync ? WriteValueAsync(value, false, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -796,7 +796,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(double? value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(double? value, CancellationToken cancellationToken = default)
{
return _safeAsync ? (value.HasValue ? WriteValueAsync(value.GetValueOrDefault(), true, cancellationToken) : WriteNullAsync(cancellationToken)) : base.WriteValueAsync(value, cancellationToken);
}
@@ -809,7 +809,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(float value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(float value, CancellationToken cancellationToken = default)
{
return _safeAsync ? WriteValueAsync(value, false, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -827,7 +827,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(float? value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(float? value, CancellationToken cancellationToken = default)
{
return _safeAsync ? (value.HasValue ? WriteValueAsync(value.GetValueOrDefault(), true, cancellationToken) : WriteNullAsync(cancellationToken)) : base.WriteValueAsync(value, cancellationToken);
}
@@ -840,7 +840,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(Guid value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(Guid value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -866,7 +866,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(Guid? value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(Guid? value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -884,7 +884,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(int value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(int value, CancellationToken cancellationToken = default)
{
return _safeAsync ? WriteIntegerValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -897,7 +897,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(int? value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(int? value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -915,7 +915,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(long value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(long value, CancellationToken cancellationToken = default)
{
return _safeAsync ? WriteIntegerValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -928,7 +928,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(long? value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(long? value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -953,7 +953,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(object value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(object value, CancellationToken cancellationToken = default)
{
if (_safeAsync)
{
@@ -983,7 +983,7 @@ namespace Newtonsoft.Json
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
[CLSCompliant(false)]
public override Task WriteValueAsync(sbyte value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(sbyte value, CancellationToken cancellationToken = default)
{
return _safeAsync ? WriteIntegerValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -997,7 +997,7 @@ namespace Newtonsoft.Json
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
[CLSCompliant(false)]
public override Task WriteValueAsync(sbyte? value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(sbyte? value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -1015,7 +1015,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(short value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(short value, CancellationToken cancellationToken = default)
{
return _safeAsync ? WriteIntegerValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -1028,7 +1028,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(short? value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(short? value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -1046,7 +1046,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(string value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(string value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -1076,7 +1076,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(TimeSpan value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(TimeSpan value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -1097,7 +1097,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(TimeSpan? value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(TimeSpan? value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -1116,7 +1116,7 @@ namespace Newtonsoft.Json
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
[CLSCompliant(false)]
public override Task WriteValueAsync(uint value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(uint value, CancellationToken cancellationToken = default)
{
return _safeAsync ? WriteIntegerValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -1130,7 +1130,7 @@ namespace Newtonsoft.Json
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
[CLSCompliant(false)]
public override Task WriteValueAsync(uint? value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(uint? value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -1149,7 +1149,7 @@ namespace Newtonsoft.Json
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
[CLSCompliant(false)]
public override Task WriteValueAsync(ulong value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(ulong value, CancellationToken cancellationToken = default)
{
return _safeAsync ? WriteIntegerValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -1163,7 +1163,7 @@ namespace Newtonsoft.Json
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
[CLSCompliant(false)]
public override Task WriteValueAsync(ulong? value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(ulong? value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -1181,7 +1181,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteValueAsync(Uri value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(Uri value, CancellationToken cancellationToken = default)
{
return _safeAsync ? (value == null ? WriteNullAsync(cancellationToken) : WriteValueNotNullAsync(value, cancellationToken)) : base.WriteValueAsync(value, cancellationToken);
}
@@ -1212,7 +1212,7 @@ namespace Newtonsoft.Json
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
[CLSCompliant(false)]
public override Task WriteValueAsync(ushort value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(ushort value, CancellationToken cancellationToken = default)
{
return _safeAsync ? WriteIntegerValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -1226,7 +1226,7 @@ namespace Newtonsoft.Json
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
[CLSCompliant(false)]
public override Task WriteValueAsync(ushort? value, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteValueAsync(ushort? value, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteValueAsync(value, cancellationToken) : base.WriteValueAsync(value, cancellationToken);
}
@@ -1244,7 +1244,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteCommentAsync(string text, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteCommentAsync(string text, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteCommentAsync(text, cancellationToken) : base.WriteCommentAsync(text, cancellationToken);
}
@@ -1264,7 +1264,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteEndArrayAsync(CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteEndArrayAsync(CancellationToken cancellationToken = default)
{
return _safeAsync ? InternalWriteEndAsync(JsonContainerType.Array, cancellationToken) : base.WriteEndArrayAsync(cancellationToken);
}
@@ -1276,7 +1276,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteEndConstructorAsync(CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteEndConstructorAsync(CancellationToken cancellationToken = default)
{
return _safeAsync ? InternalWriteEndAsync(JsonContainerType.Constructor, cancellationToken) : base.WriteEndConstructorAsync(cancellationToken);
}
@@ -1288,7 +1288,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteEndObjectAsync(CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteEndObjectAsync(CancellationToken cancellationToken = default)
{
return _safeAsync ? InternalWriteEndAsync(JsonContainerType.Object, cancellationToken) : base.WriteEndObjectAsync(cancellationToken);
}
@@ -1301,7 +1301,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>Derived classes must override this method to get asynchronous behaviour. Otherwise it will
/// execute synchronously, returning an already-completed task.</remarks>
public override Task WriteRawValueAsync(string json, CancellationToken cancellationToken = default(CancellationToken))
public override Task WriteRawValueAsync(string json, CancellationToken cancellationToken = default)
{
return _safeAsync ? DoWriteRawValueAsync(json, cancellationToken) : base.WriteRawValueAsync(json, cancellationToken);
}
+2 -2
View File
@@ -390,10 +390,10 @@ namespace Newtonsoft.Json
public override void WriteValue(object value)
{
#if HAVE_BIG_INTEGER
if (value is BigInteger)
if (value is BigInteger i)
{
InternalWriteValue(JsonToken.Integer);
WriteValueInternal(((BigInteger)value).ToString(CultureInfo.InvariantCulture), JsonToken.String);
WriteValueInternal(i.ToString(CultureInfo.InvariantCulture), JsonToken.String);
}
else
#endif
+47 -64
View File
@@ -186,72 +186,71 @@ namespace Newtonsoft.Json
case JTokenType.None:
return _currentScope.Schemas;
case JTokenType.Object:
{
if (_currentScope.CurrentPropertyName == null)
{
throw new JsonReaderException("CurrentPropertyName has not been set on scope.");
}
IList<JsonSchemaModel> schemas = new List<JsonSchemaModel>();
foreach (JsonSchemaModel schema in CurrentSchemas)
{
JsonSchemaModel propertySchema;
if (schema.Properties != null && schema.Properties.TryGetValue(_currentScope.CurrentPropertyName, out propertySchema))
if (_currentScope.CurrentPropertyName == null)
{
schemas.Add(propertySchema);
throw new JsonReaderException("CurrentPropertyName has not been set on scope.");
}
if (schema.PatternProperties != null)
IList<JsonSchemaModel> schemas = new List<JsonSchemaModel>();
foreach (JsonSchemaModel schema in CurrentSchemas)
{
foreach (KeyValuePair<string, JsonSchemaModel> patternProperty in schema.PatternProperties)
if (schema.Properties != null && schema.Properties.TryGetValue(_currentScope.CurrentPropertyName, out JsonSchemaModel propertySchema))
{
if (Regex.IsMatch(_currentScope.CurrentPropertyName, patternProperty.Key))
schemas.Add(propertySchema);
}
if (schema.PatternProperties != null)
{
foreach (KeyValuePair<string, JsonSchemaModel> patternProperty in schema.PatternProperties)
{
schemas.Add(patternProperty.Value);
if (Regex.IsMatch(_currentScope.CurrentPropertyName, patternProperty.Key))
{
schemas.Add(patternProperty.Value);
}
}
}
if (schemas.Count == 0 && schema.AllowAdditionalProperties && schema.AdditionalProperties != null)
{
schemas.Add(schema.AdditionalProperties);
}
}
if (schemas.Count == 0 && schema.AllowAdditionalProperties && schema.AdditionalProperties != null)
{
schemas.Add(schema.AdditionalProperties);
}
return schemas;
}
return schemas;
}
case JTokenType.Array:
{
IList<JsonSchemaModel> schemas = new List<JsonSchemaModel>();
foreach (JsonSchemaModel schema in CurrentSchemas)
{
if (!schema.PositionalItemsValidation)
IList<JsonSchemaModel> schemas = new List<JsonSchemaModel>();
foreach (JsonSchemaModel schema in CurrentSchemas)
{
if (schema.Items != null && schema.Items.Count > 0)
if (!schema.PositionalItemsValidation)
{
schemas.Add(schema.Items[0]);
}
}
else
{
if (schema.Items != null && schema.Items.Count > 0)
{
if (schema.Items.Count > (_currentScope.ArrayItemCount - 1))
if (schema.Items != null && schema.Items.Count > 0)
{
schemas.Add(schema.Items[_currentScope.ArrayItemCount - 1]);
schemas.Add(schema.Items[0]);
}
}
if (schema.AllowAdditionalItems && schema.AdditionalItems != null)
else
{
schemas.Add(schema.AdditionalItems);
if (schema.Items != null && schema.Items.Count > 0)
{
if (schema.Items.Count > (_currentScope.ArrayItemCount - 1))
{
schemas.Add(schema.Items[_currentScope.ArrayItemCount - 1]);
}
}
if (schema.AllowAdditionalItems && schema.AdditionalItems != null)
{
schemas.Add(schema.AdditionalItems);
}
}
}
}
return schemas;
}
return schemas;
}
case JTokenType.Constructor:
return EmptySchemaList;
default:
@@ -823,11 +822,10 @@ namespace Newtonsoft.Json
{
bool notDivisible;
#if HAVE_BIG_INTEGER
if (value is BigInteger)
if (value is BigInteger i)
{
// not that this will lose any decimal point on DivisibleBy
// so manually raise an error if DivisibleBy is not an integer and value is not zero
BigInteger i = (BigInteger)value;
bool divisibleNonInteger = !Math.Abs(schema.DivisibleBy.Value - Math.Truncate(schema.DivisibleBy.Value)).Equals(0);
if (divisibleNonInteger)
{
@@ -1015,26 +1013,11 @@ namespace Newtonsoft.Json
bool IJsonLineInfo.HasLineInfo()
{
IJsonLineInfo lineInfo = _reader as IJsonLineInfo;
return lineInfo != null && lineInfo.HasLineInfo();
return _reader is IJsonLineInfo lineInfo && lineInfo.HasLineInfo();
}
int IJsonLineInfo.LineNumber
{
get
{
IJsonLineInfo lineInfo = _reader as IJsonLineInfo;
return (lineInfo != null) ? lineInfo.LineNumber : 0;
}
}
int IJsonLineInfo.LineNumber => (_reader is IJsonLineInfo lineInfo) ? lineInfo.LineNumber : 0;
int IJsonLineInfo.LinePosition
{
get
{
IJsonLineInfo lineInfo = _reader as IJsonLineInfo;
return (lineInfo != null) ? lineInfo.LinePosition : 0;
}
}
int IJsonLineInfo.LinePosition => (_reader is IJsonLineInfo lineInfo) ? lineInfo.LinePosition : 0;
}
}
+61 -61
View File
@@ -115,7 +115,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task CloseAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task CloseAsync(CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -133,7 +133,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task FlushAsync(CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -225,7 +225,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteRawAsync(string json, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteRawAsync(string json, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -243,7 +243,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteEndAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteEndAsync(CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -398,7 +398,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteEndArrayAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteEndArrayAsync(CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -416,7 +416,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteEndConstructorAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteEndConstructorAsync(CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -434,7 +434,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteEndObjectAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteEndObjectAsync(CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -452,7 +452,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteNullAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteNullAsync(CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -471,7 +471,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WritePropertyNameAsync(string name, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WritePropertyNameAsync(string name, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -491,7 +491,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WritePropertyNameAsync(string name, bool escape, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WritePropertyNameAsync(string name, bool escape, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -520,7 +520,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteStartArrayAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteStartArrayAsync(CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -546,7 +546,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteCommentAsync(string text, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteCommentAsync(string text, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -570,7 +570,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteRawValueAsync(string json, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteRawValueAsync(string json, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -589,7 +589,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteStartConstructorAsync(string name, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteStartConstructorAsync(string name, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -607,7 +607,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteStartObjectAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteStartObjectAsync(CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -626,7 +626,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public Task WriteTokenAsync(JsonReader reader, CancellationToken cancellationToken = default(CancellationToken))
public Task WriteTokenAsync(JsonReader reader, CancellationToken cancellationToken = default)
{
return WriteTokenAsync(reader, true, cancellationToken);
}
@@ -640,7 +640,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public Task WriteTokenAsync(JsonReader reader, bool writeChildren, CancellationToken cancellationToken = default(CancellationToken))
public Task WriteTokenAsync(JsonReader reader, bool writeChildren, CancellationToken cancellationToken = default)
{
ValidationUtils.ArgumentNotNull(reader, nameof(reader));
@@ -655,7 +655,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public Task WriteTokenAsync(JsonToken token, CancellationToken cancellationToken = default(CancellationToken))
public Task WriteTokenAsync(JsonToken token, CancellationToken cancellationToken = default)
{
return WriteTokenAsync(token, null, cancellationToken);
}
@@ -673,7 +673,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public Task WriteTokenAsync(JsonToken token, object value, CancellationToken cancellationToken = default(CancellationToken))
public Task WriteTokenAsync(JsonToken token, object value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -853,7 +853,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(bool value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(bool value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -872,7 +872,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(bool? value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(bool? value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -891,7 +891,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(byte value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(byte value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -910,7 +910,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(byte? value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(byte? value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -929,7 +929,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(byte[] value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(byte[] value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -948,7 +948,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(char value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(char value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -967,7 +967,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(char? value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(char? value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -986,7 +986,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(DateTime value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(DateTime value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1005,7 +1005,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(DateTime? value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(DateTime? value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1024,7 +1024,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(DateTimeOffset value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(DateTimeOffset value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1043,7 +1043,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(DateTimeOffset? value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(DateTimeOffset? value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1062,7 +1062,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(decimal value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(decimal value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1081,7 +1081,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(decimal? value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(decimal? value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1100,7 +1100,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(double value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(double value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1119,7 +1119,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(double? value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(double? value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1138,7 +1138,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(float value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(float value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1157,7 +1157,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(float? value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(float? value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1176,7 +1176,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(Guid value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(Guid value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1195,7 +1195,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(Guid? value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(Guid? value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1214,7 +1214,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(int value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(int value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1233,7 +1233,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(int? value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(int? value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1252,7 +1252,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(long value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(long value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1271,7 +1271,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(long? value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(long? value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1290,7 +1290,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(object value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(object value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1310,7 +1310,7 @@ namespace Newtonsoft.Json
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
[CLSCompliant(false)]
public virtual Task WriteValueAsync(sbyte value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(sbyte value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1330,7 +1330,7 @@ namespace Newtonsoft.Json
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
[CLSCompliant(false)]
public virtual Task WriteValueAsync(sbyte? value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(sbyte? value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1349,7 +1349,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(short value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(short value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1368,7 +1368,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(short? value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(short? value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1387,7 +1387,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(string value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(string value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1406,7 +1406,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(TimeSpan value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(TimeSpan value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1425,7 +1425,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(TimeSpan? value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(TimeSpan? value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1445,7 +1445,7 @@ namespace Newtonsoft.Json
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
[CLSCompliant(false)]
public virtual Task WriteValueAsync(uint value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(uint value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1465,7 +1465,7 @@ namespace Newtonsoft.Json
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
[CLSCompliant(false)]
public virtual Task WriteValueAsync(uint? value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(uint? value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1485,7 +1485,7 @@ namespace Newtonsoft.Json
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
[CLSCompliant(false)]
public virtual Task WriteValueAsync(ulong value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(ulong value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1505,7 +1505,7 @@ namespace Newtonsoft.Json
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
[CLSCompliant(false)]
public virtual Task WriteValueAsync(ulong? value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(ulong? value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1524,7 +1524,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteValueAsync(Uri value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(Uri value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1544,7 +1544,7 @@ namespace Newtonsoft.Json
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
[CLSCompliant(false)]
public virtual Task WriteValueAsync(ushort value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(ushort value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1564,7 +1564,7 @@ namespace Newtonsoft.Json
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
[CLSCompliant(false)]
public virtual Task WriteValueAsync(ushort? value, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteValueAsync(ushort? value, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1582,7 +1582,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteUndefinedAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteUndefinedAsync(CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1601,7 +1601,7 @@ namespace Newtonsoft.Json
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
/// classes can override this behaviour for true asynchronicity.</remarks>
public virtual Task WriteWhitespaceAsync(string ws, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task WriteWhitespaceAsync(string ws, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -1648,12 +1648,12 @@ namespace Newtonsoft.Json
case JsonToken.StartConstructor:
return InternalWriteStartAsync(token, JsonContainerType.Constructor, cancellationToken);
case JsonToken.PropertyName:
if (!(value is string))
if (!(value is string s))
{
throw new ArgumentException("A name is required when setting property name state.", nameof(value));
}
return InternalWritePropertyNameAsync((string)value, cancellationToken);
return InternalWritePropertyNameAsync(s, cancellationToken);
case JsonToken.Comment:
return InternalWriteCommentAsync(cancellationToken);
case JsonToken.Raw:
+8 -8
View File
@@ -561,17 +561,17 @@ namespace Newtonsoft.Json
break;
case JsonToken.Float:
ValidationUtils.ArgumentNotNull(value, nameof(value));
if (value is decimal d)
if (value is decimal decimalValue)
{
WriteValue(d);
WriteValue(decimalValue);
}
else if (value is double)
else if (value is double doubleValue)
{
WriteValue((double)value);
WriteValue(doubleValue);
}
else if (value is float)
else if (value is float floatValue)
{
WriteValue((float)value);
WriteValue(floatValue);
}
else
{
@@ -1697,12 +1697,12 @@ namespace Newtonsoft.Json
InternalWriteStart(token, JsonContainerType.Constructor);
break;
case JsonToken.PropertyName:
if (!(value is string))
if (!(value is string s))
{
throw new ArgumentException("A name is required when setting property name state.", nameof(value));
}
InternalWritePropertyName((string)value);
InternalWritePropertyName(s);
break;
case JsonToken.Comment:
InternalWriteComment();
+8 -11
View File
@@ -187,8 +187,7 @@ namespace Newtonsoft.Json.Linq
{
foreach (T token in source)
{
JValue value = token as JValue;
if (value != null)
if (token is JValue value)
{
yield return Convert<JValue, U>(value);
}
@@ -256,20 +255,18 @@ namespace Newtonsoft.Json.Linq
{
if (token == null)
{
return default(U);
return default;
}
if (token is U
if (token is U castValue
// don't want to cast JValue to its interfaces, want to get the internal value
&& typeof(U) != typeof(IComparable) && typeof(U) != typeof(IFormattable))
{
// HACK
return (U)(object)token;
return castValue;
}
else
{
JValue value = token as JValue;
if (value == null)
if (!(token is JValue value))
{
throw new InvalidCastException("Cannot cast {0} to {1}.".FormatWith(CultureInfo.InvariantCulture, token.GetType(), typeof(T)));
}
@@ -285,7 +282,7 @@ namespace Newtonsoft.Json.Linq
{
if (value.Value == null)
{
return default(U);
return default;
}
targetType = Nullable.GetUnderlyingType(targetType);
@@ -320,9 +317,9 @@ namespace Newtonsoft.Json.Linq
{
return null;
}
else if (source is IJEnumerable<T>)
else if (source is IJEnumerable<T> customEnumerable)
{
return (IJEnumerable<T>)source;
return customEnumerable;
}
else
{
+2 -2
View File
@@ -60,7 +60,7 @@ namespace Newtonsoft.Json.Linq
/// If this is <c>null</c>, default load settings will be used.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
/// <returns>A <see cref="Task{TResult}"/> representing the asynchronous load. The <see cref="Task{TResult}.Result"/> property contains the JSON that was read from the specified <see cref="JsonReader"/>.</returns>
public new static Task<JArray> LoadAsync(JsonReader reader, CancellationToken cancellationToken = default(CancellationToken))
public new static Task<JArray> LoadAsync(JsonReader reader, CancellationToken cancellationToken = default)
{
return LoadAsync(reader, null, cancellationToken);
}
@@ -73,7 +73,7 @@ namespace Newtonsoft.Json.Linq
/// If this is <c>null</c>, default load settings will be used.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
/// <returns>A <see cref="Task{TResult}"/> representing the asynchronous load. The <see cref="Task{TResult}.Result"/> property contains the JSON that was read from the specified <see cref="JsonReader"/>.</returns>
public new static async Task<JArray> LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default(CancellationToken))
public new static async Task<JArray> LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default)
{
if (reader.TokenType == JsonToken.None)
{
@@ -61,7 +61,7 @@ namespace Newtonsoft.Json.Linq
/// <returns>
/// A <see cref="Task{TResult}"/> that represents the asynchronous load. The <see cref="Task{TResult}.Result"/>
/// property returns a <see cref="JConstructor"/> that contains the JSON that was read from the specified <see cref="JsonReader"/>.</returns>
public new static Task<JConstructor> LoadAsync(JsonReader reader, CancellationToken cancellationToken = default(CancellationToken))
public new static Task<JConstructor> LoadAsync(JsonReader reader, CancellationToken cancellationToken = default)
{
return LoadAsync(reader, null, cancellationToken);
}
@@ -76,7 +76,7 @@ namespace Newtonsoft.Json.Linq
/// <returns>
/// A <see cref="Task{TResult}"/> that represents the asynchronous load. The <see cref="Task{TResult}.Result"/>
/// property returns a <see cref="JConstructor"/> that contains the JSON that was read from the specified <see cref="JsonReader"/>.</returns>
public new static async Task<JConstructor> LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default(CancellationToken))
public new static async Task<JConstructor> LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default)
{
if (reader.TokenType == JsonToken.None)
{
+4 -4
View File
@@ -175,23 +175,23 @@ namespace Newtonsoft.Json.Linq
{
ValidationUtils.ArgumentNotNull(key, nameof(key));
if (!(key is int))
if (!(key is int i))
{
throw new ArgumentException("Accessed JConstructor values with invalid key value: {0}. Argument position index expected.".FormatWith(CultureInfo.InvariantCulture, MiscellaneousUtils.ToString(key)));
}
return GetItem((int)key);
return GetItem(i);
}
set
{
ValidationUtils.ArgumentNotNull(key, nameof(key));
if (!(key is int))
if (!(key is int i))
{
throw new ArgumentException("Set JConstructor values with invalid key value: {0}. Argument position index expected.".FormatWith(CultureInfo.InvariantCulture, MiscellaneousUtils.ToString(key)));
}
SetItem((int)key, value);
SetItem(i, value);
}
}
+3 -3
View File
@@ -35,7 +35,7 @@ namespace Newtonsoft.Json.Linq
{
public abstract partial class JContainer
{
internal async Task ReadTokenFromAsync(JsonReader reader, JsonLoadSettings options, CancellationToken cancellationToken = default(CancellationToken))
internal async Task ReadTokenFromAsync(JsonReader reader, JsonLoadSettings options, CancellationToken cancellationToken = default)
{
ValidationUtils.ArgumentNotNull(reader, nameof(reader));
int startDepth = reader.Depth;
@@ -53,7 +53,7 @@ namespace Newtonsoft.Json.Linq
}
}
private async Task ReadContentFromAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default(CancellationToken))
private async Task ReadContentFromAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default)
{
IJsonLineInfo lineInfo = reader as IJsonLineInfo;
@@ -61,7 +61,7 @@ namespace Newtonsoft.Json.Linq
do
{
if ((parent as JProperty)?.Value != null)
if (parent is JProperty p && p.Value != null)
{
if (parent == this)
{
+2 -3
View File
@@ -750,7 +750,7 @@ namespace Newtonsoft.Json.Linq
do
{
if ((parent as JProperty)?.Value != null)
if (parent is JProperty p && p.Value != null)
{
if (parent == this)
{
@@ -1041,12 +1041,11 @@ namespace Newtonsoft.Json.Linq
throw new JsonException("Could not determine new value to add to '{0}'.".FormatWith(CultureInfo.InvariantCulture, GetType()));
}
if (!(args.NewObject is JToken))
if (!(args.NewObject is JToken newItem))
{
throw new JsonException("New item to be added to collection must be compatible with {0}.".FormatWith(CultureInfo.InvariantCulture, typeof(JToken)));
}
JToken newItem = (JToken)args.NewObject;
Add(newItem);
return newItem;
+2 -2
View File
@@ -82,7 +82,7 @@ namespace Newtonsoft.Json.Linq
/// <returns>
/// A <see cref="Task{TResult}"/> that represents the asynchronous load. The <see cref="Task{TResult}.Result"/>
/// property returns a <see cref="JObject"/> that contains the JSON that was read from the specified <see cref="JsonReader"/>.</returns>
public new static Task<JObject> LoadAsync(JsonReader reader, CancellationToken cancellationToken = default(CancellationToken))
public new static Task<JObject> LoadAsync(JsonReader reader, CancellationToken cancellationToken = default)
{
return LoadAsync(reader, null, cancellationToken);
}
@@ -97,7 +97,7 @@ namespace Newtonsoft.Json.Linq
/// <returns>
/// A <see cref="Task{TResult}"/> that represents the asynchronous load. The <see cref="Task{TResult}.Result"/>
/// property returns a <see cref="JObject"/> that contains the JSON that was read from the specified <see cref="JsonReader"/>.</returns>
public new static async Task<JObject> LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default(CancellationToken))
public new static async Task<JObject> LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default)
{
ValidationUtils.ArgumentNotNull(reader, nameof(reader));
+2 -2
View File
@@ -74,7 +74,7 @@ namespace Newtonsoft.Json.Linq
/// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
/// <returns>A <see cref="Task{TResult}"/> representing the asynchronous creation. The <see cref="Task{TResult}.Result"/>
/// property returns a <see cref="JProperty"/> that contains the JSON that was read from the specified <see cref="JsonReader"/>.</returns>
public new static Task<JProperty> LoadAsync(JsonReader reader, CancellationToken cancellationToken = default(CancellationToken))
public new static Task<JProperty> LoadAsync(JsonReader reader, CancellationToken cancellationToken = default)
{
return LoadAsync(reader, null, cancellationToken);
}
@@ -88,7 +88,7 @@ namespace Newtonsoft.Json.Linq
/// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
/// <returns>A <see cref="Task{TResult}"/> representing the asynchronous creation. The <see cref="Task{TResult}.Result"/>
/// property returns a <see cref="JProperty"/> that contains the JSON that was read from the specified <see cref="JsonReader"/>.</returns>
public new static async Task<JProperty> LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default(CancellationToken))
public new static async Task<JProperty> LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default)
{
if (reader.TokenType == JsonToken.None)
{
+1 -1
View File
@@ -41,7 +41,7 @@ namespace Newtonsoft.Json.Linq
/// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
/// <returns>A <see cref="Task{TResult}"/> representing the asynchronous creation. The <see cref="Task{TResult}.Result"/>
/// property returns an instance of <see cref="JRaw"/> with the content of the reader's current token.</returns>
public static async Task<JRaw> CreateAsync(JsonReader reader, CancellationToken cancellationToken = default(CancellationToken))
public static async Task<JRaw> CreateAsync(JsonReader reader, CancellationToken cancellationToken = default)
{
using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture))
using (JsonTextWriter jsonWriter = new JsonTextWriter(sw))
+5 -5
View File
@@ -55,7 +55,7 @@ namespace Newtonsoft.Json.Linq
/// <returns>A <see cref="Task"/> that represents the asynchronous write operation.</returns>
public Task WriteToAsync(JsonWriter writer, params JsonConverter[] converters)
{
return WriteToAsync(writer, default(CancellationToken), converters);
return WriteToAsync(writer, default, converters);
}
/// <summary>
@@ -70,7 +70,7 @@ namespace Newtonsoft.Json.Linq
/// that were read from the reader. The runtime type of the token is determined
/// by the token type of the first token encountered in the reader.
/// </returns>
public static Task<JToken> ReadFromAsync(JsonReader reader, CancellationToken cancellationToken = default(CancellationToken))
public static Task<JToken> ReadFromAsync(JsonReader reader, CancellationToken cancellationToken = default)
{
return ReadFromAsync(reader, null, cancellationToken);
}
@@ -89,7 +89,7 @@ namespace Newtonsoft.Json.Linq
/// that were read from the reader. The runtime type of the token is determined
/// by the token type of the first token encountered in the reader.
/// </returns>
public static async Task<JToken> ReadFromAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default(CancellationToken))
public static async Task<JToken> ReadFromAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default)
{
ValidationUtils.ArgumentNotNull(reader, nameof(reader));
@@ -150,7 +150,7 @@ namespace Newtonsoft.Json.Linq
/// that were read from the reader. The runtime type of the token is determined
/// by the token type of the first token encountered in the reader.
/// </returns>
public static Task<JToken> LoadAsync(JsonReader reader, CancellationToken cancellationToken = default(CancellationToken))
public static Task<JToken> LoadAsync(JsonReader reader, CancellationToken cancellationToken = default)
{
return LoadAsync(reader, null, cancellationToken);
}
@@ -168,7 +168,7 @@ namespace Newtonsoft.Json.Linq
/// that were read from the reader. The runtime type of the token is determined
/// by the token type of the first token encountered in the reader.
/// </returns>
public static Task<JToken> LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default(CancellationToken))
public static Task<JToken> LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default)
{
return ReadFromAsync(reader, settings, cancellationToken);
}
+4 -4
View File
@@ -333,7 +333,7 @@ namespace Newtonsoft.Json.Linq
JToken token = this[key];
// null check to fix MonoTouch issue - https://github.com/dolbz/Newtonsoft.Json/commit/a24e3062846b30ee505f3271ac08862bb471b822
return token == null ? default(T) : Extensions.Convert<JToken, T>(token);
return token == null ? default : Extensions.Convert<JToken, T>(token);
}
/// <summary>
@@ -462,9 +462,9 @@ namespace Newtonsoft.Json.Linq
{
ValidationUtils.ArgumentNotNull(token, nameof(token));
if (token is JProperty)
if (token is JProperty p)
{
token = ((JProperty)token).Value;
token = p.Value;
}
return token.Type.ToString();
@@ -2461,7 +2461,7 @@ namespace Newtonsoft.Json.Linq
}
}
return default(T);
return default;
}
/// <summary>
+1 -2
View File
@@ -232,8 +232,7 @@ namespace Newtonsoft.Json.Linq
case JTokenType.Uri:
{
object v = ((JValue)token).Value;
Uri uri = v as Uri;
SetToken(JsonToken.String, uri != null ? uri.OriginalString : SafeToString(v));
SetToken(JsonToken.String, v is Uri uri ? uri.OriginalString : SafeToString(v));
break;
}
case JTokenType.TimeSpan:
+1 -2
View File
@@ -1030,10 +1030,9 @@ namespace Newtonsoft.Json.Linq
return 1;
}
JValue value = obj as JValue;
JTokenType comparisonType;
object otherValue;
if (value != null)
if (obj is JValue value)
{
otherValue = value.Value;
comparisonType = (_valueType == JTokenType.String && _valueType != value._valueType)
@@ -120,8 +120,7 @@ namespace Newtonsoft.Json.Schema
}
else if (currentToken.Type == JTokenType.Array || currentToken.Type == JTokenType.Constructor)
{
int index;
if (int.TryParse(part, out index) && index >= 0 && index < currentToken.Count())
if (int.TryParse(part, out int index) && index >= 0 && index < currentToken.Count())
{
currentToken = currentToken[index];
}
@@ -206,14 +205,12 @@ namespace Newtonsoft.Json.Schema
private JsonSchema BuildSchema(JToken token)
{
JObject schemaObject = token as JObject;
if (schemaObject == null)
if (!(token is JObject schemaObject))
{
throw JsonException.Create(token, token.Path, "Expected object while parsing schema object, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type));
}
JToken referenceToken;
if (schemaObject.TryGetValue(JsonTypeReflector.RefPropertyName, out referenceToken))
if (schemaObject.TryGetValue(JsonTypeReflector.RefPropertyName, out JToken referenceToken))
{
JsonSchema deferredSchema = new JsonSchema();
deferredSchema.DeferredReference = (string)referenceToken;
@@ -228,8 +225,7 @@ namespace Newtonsoft.Json.Schema
}
location = "#" + location;
JsonSchema existingSchema;
if (_documentSchemas.TryGetValue(location, out existingSchema))
if (_documentSchemas.TryGetValue(location, out JsonSchema existingSchema))
{
return existingSchema;
}
@@ -475,8 +471,7 @@ namespace Newtonsoft.Json.Schema
internal static JsonSchemaType MapType(string type)
{
JsonSchemaType mappedType;
if (!JsonSchemaConstants.JsonSchemaTypeMapping.TryGetValue(type, out mappedType))
if (!JsonSchemaConstants.JsonSchemaTypeMapping.TryGetValue(type, out JsonSchemaType mappedType))
{
throw new JsonException("Invalid JSON schema type: {0}".FormatWith(CultureInfo.InvariantCulture, type));
}
@@ -126,8 +126,7 @@ namespace Newtonsoft.Json.Schema
public void AddProperty(IDictionary<string, JsonSchemaNode> target, string propertyName, JsonSchema schema)
{
JsonSchemaNode propertyNode;
target.TryGetValue(propertyName, out propertyNode);
target.TryGetValue(propertyName, out JsonSchemaNode propertyNode);
target[propertyName] = AddSchema(propertyNode, schema);
}
@@ -162,8 +161,7 @@ namespace Newtonsoft.Json.Schema
private JsonSchemaModel BuildNodeModel(JsonSchemaNode node)
{
JsonSchemaModel model;
if (_nodeModels.TryGetValue(node, out model))
if (_nodeModels.TryGetValue(node, out JsonSchemaModel model))
{
return model;
}
@@ -48,12 +48,12 @@ namespace Newtonsoft.Json.Serialization
public override bool Equals(object obj)
{
if (!(obj is ResolverContractKey))
if (!(obj is ResolverContractKey key))
{
return false;
}
return Equals((ResolverContractKey)obj);
return Equals(key);
}
public bool Equals(ResolverContractKey other)
@@ -96,10 +96,9 @@ namespace Newtonsoft.Json.Serialization
}
// for backwards compadibility the CamelCasePropertyNamesContractResolver shares contracts between instances
JsonContract contract;
ResolverContractKey key = new ResolverContractKey(GetType(), type);
Dictionary<ResolverContractKey, JsonContract> cache = _contractCache;
if (cache == null || !cache.TryGetValue(key, out contract))
if (cache == null || !cache.TryGetValue(key, out JsonContract contract))
{
contract = CreateContract(type);
@@ -119,7 +119,7 @@ namespace Newtonsoft.Json.Serialization
[Obsolete("DefaultMembersSearchFlags is obsolete. To modify the members serialized inherit from DefaultContractResolver and override the GetSerializableMembers method instead.")]
public BindingFlags DefaultMembersSearchFlags { get; set; }
#else
private BindingFlags DefaultMembersSearchFlags;
private readonly BindingFlags DefaultMembersSearchFlags;
#endif
/// <summary>
@@ -267,9 +267,8 @@ namespace Newtonsoft.Json.Serialization
}
#if HAVE_DATA_CONTRACTS
Type match;
// don't include EntityKey on entities objects... this is a bit hacky
if (objectType.AssignableToTypeName("System.Data.Objects.DataClasses.EntityObject", false, out match))
if (objectType.AssignableToTypeName("System.Data.Objects.DataClasses.EntityObject", false, out _))
{
serializableMembers = serializableMembers.Where(ShouldSerializeEntityMember).ToList();
}
@@ -293,8 +292,7 @@ namespace Newtonsoft.Json.Serialization
#if HAVE_DATA_CONTRACTS
private bool ShouldSerializeEntityMember(MemberInfo memberInfo)
{
PropertyInfo propertyInfo = memberInfo as PropertyInfo;
if (propertyInfo != null)
if (memberInfo is PropertyInfo propertyInfo)
{
if (propertyInfo.PropertyType.IsGenericType() && propertyInfo.PropertyType.GetGenericTypeDefinition().FullName == "System.Data.Objects.DataClasses.EntityReference`1")
{
@@ -72,9 +72,9 @@ namespace Newtonsoft.Json.Serialization
{
ValidationUtils.ArgumentNotNull(value, nameof(value));
if (value is JValue)
if (value is JValue v)
{
value = ((JValue)value).Value;
value = v.Value;
}
return System.Convert.ChangeType(value, typeCode, CultureInfo.InvariantCulture);
@@ -144,7 +144,7 @@ namespace Newtonsoft.Json.Serialization
{
if (Dictionary == null)
{
item = default(JsonProperty);
item = default;
return false;
}
@@ -548,9 +548,9 @@ namespace Newtonsoft.Json.Serialization
return creator(dictionary);
}
else if (dictionary is IWrappedDictionary)
else if (dictionary is IWrappedDictionary wrappedDictionary)
{
return ((IWrappedDictionary)dictionary).UnderlyingDictionary;
return wrappedDictionary.UnderlyingDictionary;
}
targetDictionary = dictionary;
@@ -898,9 +898,9 @@ namespace Newtonsoft.Json.Serialization
return creator(list);
}
}
else if (list is IWrappedCollection)
else if (list is IWrappedCollection wrappedCollection)
{
return ((IWrappedCollection)list).UnderlyingCollection;
return wrappedCollection.UnderlyingCollection;
}
value = list;
@@ -912,7 +912,7 @@ namespace Newtonsoft.Json.Serialization
throw JsonSerializationException.Create(reader, "Cannot populate list type {0}.".FormatWith(CultureInfo.InvariantCulture, contract.CreatedType));
}
value = PopulateList((arrayContract.ShouldCreateWrapper || !(existingValue is IList)) ? arrayContract.CreateWrapper(existingValue) : (IList)existingValue, reader, arrayContract, member, id);
value = PopulateList((arrayContract.ShouldCreateWrapper || !(existingValue is IList list)) ? arrayContract.CreateWrapper(existingValue) : list, reader, arrayContract, member, id);
}
return value;
@@ -986,7 +986,7 @@ namespace Newtonsoft.Json.Serialization
}
catch (Exception ex)
{
throw JsonSerializationException.Create(reader, "Error converting value {0} to type '{1}'.".FormatWith(CultureInfo.InvariantCulture, MiscellaneousUtils.FormatValueForPrint(value), targetType), ex);
throw JsonSerializationException.Create(reader, "Error converting value {0} to type '{1}'.".FormatWith(CultureInfo.InvariantCulture, MiscellaneousUtils.ToString(value), targetType), ex);
}
}
@@ -1975,9 +1975,9 @@ namespace Newtonsoft.Json.Serialization
{
propertyPresence = PropertyPresence.Null;
}
else if (v is string)
else if (v is string s)
{
propertyPresence = CoerceEmptyStringToNull(context.Property.PropertyType, context.Property.PropertyContract, (string)v)
propertyPresence = CoerceEmptyStringToNull(context.Property.PropertyType, context.Property.PropertyContract, s)
? PropertyPresence.Null
: PropertyPresence.Value;
}
@@ -191,7 +191,7 @@ namespace Newtonsoft.Json.Serialization
break;
case JsonContractType.Dictionary:
JsonDictionaryContract dictionaryContract = (JsonDictionaryContract)valueContract;
SerializeDictionary(writer, (value is IDictionary) ? (IDictionary)value : dictionaryContract.CreateWrapper(value), dictionaryContract, member, containerContract, containerProperty);
SerializeDictionary(writer, (value is IDictionary dictionary) ? dictionary : dictionaryContract.CreateWrapper(value), dictionaryContract, member, containerContract, containerProperty);
break;
#if HAVE_DYNAMIC
case JsonContractType.Dynamic:
@@ -479,8 +479,7 @@ namespace Newtonsoft.Json.Serialization
JsonContract keyContract = GetContractSafe(e.Key);
JsonContract valueContract = GetContractSafe(e.Value);
bool escape;
string propertyName = GetPropertyName(writer, e.Key, keyContract, out escape);
string propertyName = GetPropertyName(writer, e.Key, keyContract, out _);
propertyName = (contract.ExtensionDataNameResolver != null)
? contract.ExtensionDataNameResolver(propertyName)
@@ -388,8 +388,7 @@ namespace Newtonsoft.Json.Serialization
// no inheritance
return (ReflectionUtils.GetAttribute<NonSerializedAttribute>(provider, false) != null);
#else
FieldInfo fieldInfo = provider as FieldInfo;
if (fieldInfo != null && (fieldInfo.Attributes & FieldAttributes.NotSerialized) == FieldAttributes.NotSerialized)
if (provider is FieldInfo fieldInfo && (fieldInfo.Attributes & FieldAttributes.NotSerialized) == FieldAttributes.NotSerialized)
{
return true;
}
@@ -406,8 +405,7 @@ namespace Newtonsoft.Json.Serialization
// no inheritance
return (ReflectionUtils.GetAttribute<SerializableAttribute>(provider, false) != null);
#else
Type type = provider as Type;
if (type != null && (type.GetTypeInfo().Attributes & TypeAttributes.Serializable) == TypeAttributes.Serializable)
if (provider is Type type && (type.GetTypeInfo().Attributes & TypeAttributes.Serializable) == TypeAttributes.Serializable)
{
return true;
}
@@ -419,14 +417,12 @@ namespace Newtonsoft.Json.Serialization
public static T GetAttribute<T>(object provider) where T : Attribute
{
Type type = provider as Type;
if (type != null)
if (provider is Type type)
{
return GetAttribute<T>(type);
}
MemberInfo memberInfo = provider as MemberInfo;
if (memberInfo != null)
if (provider is MemberInfo memberInfo)
{
return GetAttribute<T>(memberInfo);
}
@@ -451,7 +447,7 @@ namespace Newtonsoft.Json.Serialization
#if HAVE_SECURITY_SAFE_CRITICAL_ATTRIBUTE
[SecuritySafeCritical]
#endif
get
get
{
if (_dynamicCodeGeneration == null)
{
@@ -150,20 +150,8 @@ namespace Newtonsoft.Json.Serialization
return _innerReader is IJsonLineInfo lineInfo && lineInfo.HasLineInfo();
}
int IJsonLineInfo.LineNumber
{
get
{
return (_innerReader is IJsonLineInfo lineInfo) ? lineInfo.LineNumber : 0;
}
}
int IJsonLineInfo.LineNumber => (_innerReader is IJsonLineInfo lineInfo) ? lineInfo.LineNumber : 0;
int IJsonLineInfo.LinePosition
{
get
{
return (_innerReader is IJsonLineInfo lineInfo) ? lineInfo.LinePosition : 0;
}
}
int IJsonLineInfo.LinePosition => (_innerReader is IJsonLineInfo lineInfo) ? lineInfo.LinePosition : 0;
}
}
+1 -1
View File
@@ -61,7 +61,7 @@ namespace Newtonsoft.Json.Utilities
public static Task<T> FromCanceled<T>(this CancellationToken cancellationToken)
{
Debug.Assert(cancellationToken.IsCancellationRequested);
return new Task<T>(() => default(T), cancellationToken);
return new Task<T>(() => default, cancellationToken);
}
// Task.Delay(0) is optimised as a cached task within the framework, and indeed
@@ -267,12 +267,12 @@ namespace Newtonsoft.Json.Utilities
public override bool Equals(object obj)
{
if (!(obj is TypeConvertKey))
if (!(obj is TypeConvertKey key))
{
return false;
}
return Equals((TypeConvertKey)obj);
return Equals(key);
}
public bool Equals(TypeConvertKey other)
+12 -12
View File
@@ -216,7 +216,7 @@ namespace Newtonsoft.Json.Utilities
DateTimeParser dateTimeParser = new DateTimeParser();
if (!dateTimeParser.Parse(text.Chars, text.StartIndex, text.Length))
{
dt = default(DateTime);
dt = default;
return false;
}
@@ -282,7 +282,7 @@ namespace Newtonsoft.Json.Utilities
DateTimeParser dateTimeParser = new DateTimeParser();
if (!dateTimeParser.Parse(text.Chars, text.StartIndex, text.Length))
{
dt = default(DateTimeOffset);
dt = default;
return false;
}
@@ -309,7 +309,7 @@ namespace Newtonsoft.Json.Utilities
long ticks = d.Ticks - offset.Ticks;
if (ticks < 0 || ticks > 3155378975999999999)
{
dt = default(DateTimeOffset);
dt = default;
return false;
}
@@ -373,7 +373,7 @@ namespace Newtonsoft.Json.Utilities
}
}
dt = default(DateTime);
dt = default;
return false;
}
@@ -409,7 +409,7 @@ namespace Newtonsoft.Json.Utilities
}
}
dt = default(DateTime);
dt = default;
return false;
}
@@ -446,7 +446,7 @@ namespace Newtonsoft.Json.Utilities
}
}
dt = default(DateTimeOffset);
dt = default;
return false;
}
@@ -484,7 +484,7 @@ namespace Newtonsoft.Json.Utilities
}
}
dt = default(DateTimeOffset);
dt = default;
return false;
}
#endif
@@ -523,7 +523,7 @@ namespace Newtonsoft.Json.Utilities
{
if (!TryParseMicrosoftDate(text, out long ticks, out _, out DateTimeKind kind))
{
dt = default(DateTime);
dt = default;
return false;
}
@@ -555,7 +555,7 @@ namespace Newtonsoft.Json.Utilities
return true;
}
dt = default(DateTime);
dt = default;
return false;
}
@@ -582,7 +582,7 @@ namespace Newtonsoft.Json.Utilities
return true;
}
dt = default(DateTimeOffset);
dt = default;
return false;
}
#endif
@@ -593,7 +593,7 @@ namespace Newtonsoft.Json.Utilities
if (ConvertUtils.Int32TryParse(offsetText.Chars, startIndex + 1, 2, out int hours) != ParseResult.Success)
{
offset = default(TimeSpan);
offset = default;
return false;
}
@@ -602,7 +602,7 @@ namespace Newtonsoft.Json.Utilities
{
if (ConvertUtils.Int32TryParse(offsetText.Chars, startIndex + 3, 2, out minutes) != ParseResult.Success)
{
offset = default(TimeSpan);
offset = default;
return false;
}
}
@@ -161,7 +161,7 @@ namespace Newtonsoft.Json.Utilities
{
if (!_dictionary.Contains(key))
{
value = default(TValue);
value = default;
return false;
}
else
+1 -1
View File
@@ -107,7 +107,7 @@ namespace Newtonsoft.Json.Utilities
if (selectedFlagsValues.Count == 0 && enumNameValues.Values.Any(v => v == 0))
{
selectedFlagsValues.Add(default(T));
selectedFlagsValues.Add(default);
}
return selectedFlagsValues;
@@ -142,8 +142,7 @@ namespace Newtonsoft.Json.Utilities
callExpression = Expression.Call(readParameter, (MethodInfo)method, argsExpression);
}
MethodInfo m = method as MethodInfo;
if (m != null)
if (method is MethodInfo m)
{
if (m.ReturnType != typeof(void))
{
@@ -359,7 +359,7 @@ namespace Newtonsoft.Json.Utilities
}
#if HAVE_ASYNC
public static Task WriteEscapedJavaScriptStringAsync(TextWriter writer, string s, char delimiter, bool appendDelimiters, bool[] charEscapeFlags, StringEscapeHandling stringEscapeHandling, JsonTextWriter client, char[] writeBuffer, CancellationToken cancellationToken = default(CancellationToken))
public static Task WriteEscapedJavaScriptStringAsync(TextWriter writer, string s, char delimiter, bool appendDelimiters, bool[] charEscapeFlags, StringEscapeHandling stringEscapeHandling, JsonTextWriter client, char[] writeBuffer, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -567,7 +567,7 @@ namespace Newtonsoft.Json.Utilities
public static bool TryGetDateFromConstructorJson(JsonReader reader, out DateTime dateTime, out string errorMessage)
{
dateTime = default(DateTime);
dateTime = default;
errorMessage = null;
if (!TryGetDateConstructorValue(reader, out long? t1, out errorMessage) || t1 == null)
@@ -43,8 +43,7 @@ namespace Newtonsoft.Json.Utilities
{
ValidationUtils.ArgumentNotNull(method, nameof(method));
ConstructorInfo c = method as ConstructorInfo;
if (c != null)
if (method is ConstructorInfo c)
{
// don't convert to method group to avoid medium trust issues
// https://github.com/JamesNK/Newtonsoft.Json/issues/476
@@ -62,8 +61,7 @@ namespace Newtonsoft.Json.Utilities
{
ValidationUtils.ArgumentNotNull(method, nameof(method));
ConstructorInfo c = method as ConstructorInfo;
if (c != null)
if (method is ConstructorInfo c)
{
return (o, a) => c.Invoke(a);
}
@@ -84,7 +84,7 @@ namespace Newtonsoft.Json.Utilities
return "{null}";
}
return (value is string) ? @"""" + value.ToString() + @"""" : value.ToString();
return (value is string s) ? @"""" + s + @"""" : value.ToString();
}
public static int ByteArrayCompare(byte[] a1, byte[] a2)
@@ -137,21 +137,6 @@ namespace Newtonsoft.Json.Utilities
}
}
internal static string FormatValueForPrint(object value)
{
if (value == null)
{
return "{null}";
}
if (value is string)
{
return @"""" + value + @"""";
}
return value.ToString();
}
internal static RegexOptions GetRegexOptions(string optionsText)
{
RegexOptions options = RegexOptions.None;
@@ -1113,12 +1113,12 @@ namespace Newtonsoft.Json.Utilities
public override bool Equals(object obj)
{
if (!(obj is TypeNameKey))
if (!(obj is TypeNameKey key))
{
return false;
}
return Equals((TypeNameKey)obj);
return Equals(key);
}
public bool Equals(TypeNameKey other)
+10 -11
View File
@@ -38,7 +38,7 @@ namespace Newtonsoft.Json.Utilities
{
#if DOTNET || PORTABLE
#if !DOTNET
private static BindingFlags DefaultFlags = BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
private static readonly BindingFlags DefaultFlags = BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
public static MethodInfo GetGetMethod(this PropertyInfo propertyInfo)
{
@@ -128,7 +128,7 @@ namespace Newtonsoft.Json.Utilities
}
else
{
return default(MemberTypes);
return default;
}
#endif
}
@@ -485,20 +485,20 @@ namespace Newtonsoft.Json.Utilities
private static bool TestAccessibility(MemberInfo member, BindingFlags bindingFlags)
{
if (member is FieldInfo)
if (member is FieldInfo f)
{
return TestAccessibility((FieldInfo) member, bindingFlags);
return TestAccessibility(f, bindingFlags);
}
else if (member is MethodBase)
else if (member is MethodBase m)
{
return TestAccessibility((MethodBase) member, bindingFlags);
return TestAccessibility(m, bindingFlags);
}
else if (member is PropertyInfo)
else if (member is PropertyInfo p)
{
return TestAccessibility((PropertyInfo) member, bindingFlags);
return TestAccessibility(p, bindingFlags);
}
throw new Exception("Unexpected member type.");
throw new ArgumentOutOfRangeException("Unexpected member type.");
}
private static bool TestAccessibility(FieldInfo member, BindingFlags bindingFlags)
@@ -609,8 +609,7 @@ namespace Newtonsoft.Json.Utilities
public static bool AssignableToTypeName(this Type type, string fullTypeName, bool searchInterfaces)
{
Type match;
return type.AssignableToTypeName(fullTypeName, searchInterfaces, out match);
return type.AssignableToTypeName(fullTypeName, searchInterfaces, out _);
}
public static bool ImplementInterface(this Type type, Type interfaceType)