diff --git a/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs b/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs index d4009169..815bbe11 100644 --- a/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs +++ b/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs @@ -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(); diff --git a/Src/Newtonsoft.Json/Bson/BsonWriter.cs b/Src/Newtonsoft.Json/Bson/BsonWriter.cs index 5d5500a7..3d1c0a15 100644 --- a/Src/Newtonsoft.Json/Bson/BsonWriter.cs +++ b/Src/Newtonsoft.Json/Bson/BsonWriter.cs @@ -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 diff --git a/Src/Newtonsoft.Json/Converters/ExpandoObjectConverter.cs b/Src/Newtonsoft.Json/Converters/ExpandoObjectConverter.cs index 57959328..c946692b 100644 --- a/Src/Newtonsoft.Json/Converters/ExpandoObjectConverter.cs +++ b/Src/Newtonsoft.Json/Converters/ExpandoObjectConverter.cs @@ -158,10 +158,7 @@ namespace Newtonsoft.Json.Converters /// /// true if this can write JSON; otherwise, false. /// - public override bool CanWrite - { - get { return false; } - } + public override bool CanWrite => false; } } diff --git a/Src/Newtonsoft.Json/Converters/StringEnumConverter.cs b/Src/Newtonsoft.Json/Converters/StringEnumConverter.cs index 58b67694..03f54052 100644 --- a/Src/Newtonsoft.Json/Converters/StringEnumConverter.cs +++ b/Src/Newtonsoft.Json/Converters/StringEnumConverter.cs @@ -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. diff --git a/Src/Newtonsoft.Json/JsonContainerAttribute.cs b/Src/Newtonsoft.Json/JsonContainerAttribute.cs index c04cd4b7..e5ef292d 100644 --- a/Src/Newtonsoft.Json/JsonContainerAttribute.cs +++ b/Src/Newtonsoft.Json/JsonContainerAttribute.cs @@ -125,7 +125,7 @@ namespace Newtonsoft.Json /// public bool IsReference { - get => _isReference ?? default(bool); + get => _isReference ?? default; set => _isReference = value; } @@ -137,7 +137,7 @@ namespace Newtonsoft.Json /// public bool ItemIsReference { - get => _itemIsReference ?? default(bool); + get => _itemIsReference ?? default; set => _itemIsReference = value; } @@ -147,7 +147,7 @@ namespace Newtonsoft.Json /// The reference loop handling. public ReferenceLoopHandling ItemReferenceLoopHandling { - get => _itemReferenceLoopHandling ?? default(ReferenceLoopHandling); + get => _itemReferenceLoopHandling ?? default; set => _itemReferenceLoopHandling = value; } @@ -157,7 +157,7 @@ namespace Newtonsoft.Json /// The type name handling. public TypeNameHandling ItemTypeNameHandling { - get => _itemTypeNameHandling ?? default(TypeNameHandling); + get => _itemTypeNameHandling ?? default; set => _itemTypeNameHandling = value; } diff --git a/Src/Newtonsoft.Json/JsonConverter.cs b/Src/Newtonsoft.Json/JsonConverter.cs index fc9bc256..2ac14e50 100644 --- a/Src/Newtonsoft.Json/JsonConverter.cs +++ b/Src/Newtonsoft.Json/JsonConverter.cs @@ -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); } /// diff --git a/Src/Newtonsoft.Json/JsonObjectAttribute.cs b/Src/Newtonsoft.Json/JsonObjectAttribute.cs index 82e20377..a5c35e42 100644 --- a/Src/Newtonsoft.Json/JsonObjectAttribute.cs +++ b/Src/Newtonsoft.Json/JsonObjectAttribute.cs @@ -56,7 +56,7 @@ namespace Newtonsoft.Json /// How the object's properties with null values are handled during serialization and deserialization. public NullValueHandling ItemNullValueHandling { - get => _itemNullValueHandling ?? default(NullValueHandling); + get => _itemNullValueHandling ?? default; set => _itemNullValueHandling = value; } @@ -68,7 +68,7 @@ namespace Newtonsoft.Json /// public Required ItemRequired { - get => _itemRequired ?? default(Required); + get => _itemRequired ?? default; set => _itemRequired = value; } diff --git a/Src/Newtonsoft.Json/JsonPropertyAttribute.cs b/Src/Newtonsoft.Json/JsonPropertyAttribute.cs index 56bbd865..979a43b3 100644 --- a/Src/Newtonsoft.Json/JsonPropertyAttribute.cs +++ b/Src/Newtonsoft.Json/JsonPropertyAttribute.cs @@ -92,7 +92,7 @@ namespace Newtonsoft.Json /// The null value handling. public NullValueHandling NullValueHandling { - get => _nullValueHandling ?? default(NullValueHandling); + get => _nullValueHandling ?? default; set => _nullValueHandling = value; } @@ -102,7 +102,7 @@ namespace Newtonsoft.Json /// The default value handling. public DefaultValueHandling DefaultValueHandling { - get => _defaultValueHandling ?? default(DefaultValueHandling); + get => _defaultValueHandling ?? default; set => _defaultValueHandling = value; } @@ -112,7 +112,7 @@ namespace Newtonsoft.Json /// The reference loop handling. public ReferenceLoopHandling ReferenceLoopHandling { - get => _referenceLoopHandling ?? default(ReferenceLoopHandling); + get => _referenceLoopHandling ?? default; set => _referenceLoopHandling = value; } @@ -122,7 +122,7 @@ namespace Newtonsoft.Json /// The object creation handling. public ObjectCreationHandling ObjectCreationHandling { - get => _objectCreationHandling ?? default(ObjectCreationHandling); + get => _objectCreationHandling ?? default; set => _objectCreationHandling = value; } @@ -132,7 +132,7 @@ namespace Newtonsoft.Json /// The type name handling. public TypeNameHandling TypeNameHandling { - get => _typeNameHandling ?? default(TypeNameHandling); + get => _typeNameHandling ?? default; set => _typeNameHandling = value; } @@ -142,7 +142,7 @@ namespace Newtonsoft.Json /// Whether this property's value is serialized as a reference. public bool IsReference { - get => _isReference ?? default(bool); + get => _isReference ?? default; set => _isReference = value; } @@ -152,7 +152,7 @@ namespace Newtonsoft.Json /// The numeric order of serialization. public int Order { - get => _order ?? default(int); + get => _order ?? default; set => _order = value; } @@ -180,7 +180,7 @@ namespace Newtonsoft.Json /// The collection's items reference loop handling. public ReferenceLoopHandling ItemReferenceLoopHandling { - get => _itemReferenceLoopHandling ?? default(ReferenceLoopHandling); + get => _itemReferenceLoopHandling ?? default; set => _itemReferenceLoopHandling = value; } @@ -190,7 +190,7 @@ namespace Newtonsoft.Json /// The collection's items type name handling. public TypeNameHandling ItemTypeNameHandling { - get => _itemTypeNameHandling ?? default(TypeNameHandling); + get => _itemTypeNameHandling ?? default; set => _itemTypeNameHandling = value; } @@ -200,7 +200,7 @@ namespace Newtonsoft.Json /// Whether this property's collection items are serialized as a reference. public bool ItemIsReference { - get => _itemIsReference ?? default(bool); + get => _itemIsReference ?? default; set => _itemIsReference = value; } diff --git a/Src/Newtonsoft.Json/JsonReader.Async.cs b/Src/Newtonsoft.Json/JsonReader.Async.cs index eb10e26e..e61e933a 100644 --- a/Src/Newtonsoft.Json/JsonReader.Async.cs +++ b/Src/Newtonsoft.Json/JsonReader.Async.cs @@ -43,7 +43,7 @@ namespace Newtonsoft.Json /// property returns true if the next token was read successfully; false if there are no more tokens to read. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - public virtual Task ReadAsync(CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task ReadAsync(CancellationToken cancellationToken = default) { return cancellationToken.CancelIfRequestedAsync() ?? Read().ToAsync(); } @@ -55,7 +55,7 @@ namespace Newtonsoft.Json /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 of . This result will be null at the end of an array. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - public virtual Task ReadAsBooleanAsync(CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task ReadAsBooleanAsync(CancellationToken cancellationToken = default) { return cancellationToken.CancelIfRequestedAsync() ?? Task.FromResult(ReadAsBoolean()); } @@ -101,7 +101,7 @@ namespace Newtonsoft.Json /// property returns the []. This result will be null at the end of an array. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - public virtual Task ReadAsBytesAsync(CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task ReadAsBytesAsync(CancellationToken cancellationToken = default) { return cancellationToken.CancelIfRequestedAsync() ?? Task.FromResult(ReadAsBytes()); } @@ -134,7 +134,7 @@ namespace Newtonsoft.Json /// property returns the of . This result will be null at the end of an array. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - public virtual Task ReadAsDateTimeAsync(CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task ReadAsDateTimeAsync(CancellationToken cancellationToken = default) { return cancellationToken.CancelIfRequestedAsync() ?? Task.FromResult(ReadAsDateTime()); } @@ -147,7 +147,7 @@ namespace Newtonsoft.Json /// property returns the of . This result will be null at the end of an array. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - public virtual Task ReadAsDateTimeOffsetAsync(CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task ReadAsDateTimeOffsetAsync(CancellationToken cancellationToken = default) { return cancellationToken.CancelIfRequestedAsync() ?? Task.FromResult(ReadAsDateTimeOffset()); } @@ -160,7 +160,7 @@ namespace Newtonsoft.Json /// property returns the of . This result will be null at the end of an array. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - public virtual Task ReadAsDecimalAsync(CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task ReadAsDecimalAsync(CancellationToken cancellationToken = default) { return cancellationToken.CancelIfRequestedAsync() ?? Task.FromResult(ReadAsDecimal()); } @@ -173,7 +173,7 @@ namespace Newtonsoft.Json /// property returns the of . This result will be null at the end of an array. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - public virtual Task ReadAsDoubleAsync(CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task ReadAsDoubleAsync(CancellationToken cancellationToken = default) { return Task.FromResult(ReadAsDouble()); } @@ -186,7 +186,7 @@ namespace Newtonsoft.Json /// property returns the of . This result will be null at the end of an array. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - public virtual Task ReadAsInt32Async(CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task ReadAsInt32Async(CancellationToken cancellationToken = default) { return cancellationToken.CancelIfRequestedAsync() ?? Task.FromResult(ReadAsInt32()); } @@ -199,7 +199,7 @@ namespace Newtonsoft.Json /// property returns the . This result will be null at the end of an array. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - public virtual Task ReadAsStringAsync(CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task ReadAsStringAsync(CancellationToken cancellationToken = default) { return cancellationToken.CancelIfRequestedAsync() ?? Task.FromResult(ReadAsString()); } diff --git a/Src/Newtonsoft.Json/JsonReader.cs b/Src/Newtonsoft.Json/JsonReader.cs index 9e9687dd..f827c278 100644 --- a/Src/Newtonsoft.Json/JsonReader.cs +++ b/Src/Newtonsoft.Json/JsonReader.cs @@ -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; diff --git a/Src/Newtonsoft.Json/JsonSerializer.cs b/Src/Newtonsoft.Json/JsonSerializer.cs index a960b871..d3e1d5ec 100644 --- a/Src/Newtonsoft.Json/JsonSerializer.cs +++ b/Src/Newtonsoft.Json/JsonSerializer.cs @@ -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) diff --git a/Src/Newtonsoft.Json/JsonTextReader.Async.cs b/Src/Newtonsoft.Json/JsonTextReader.Async.cs index 9a4638c4..bb18359a 100644 --- a/Src/Newtonsoft.Json/JsonTextReader.Async.cs +++ b/Src/Newtonsoft.Json/JsonTextReader.Async.cs @@ -53,7 +53,7 @@ namespace Newtonsoft.Json /// property returns true if the next token was read successfully; false if there are no more tokens to read. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - public override Task ReadAsync(CancellationToken cancellationToken = default(CancellationToken)) + public override Task ReadAsync(CancellationToken cancellationToken = default) { return _safeAsync ? DoReadAsync(cancellationToken) : base.ReadAsync(cancellationToken); } @@ -1387,7 +1387,7 @@ namespace Newtonsoft.Json /// property returns the of . This result will be null at the end of an array. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - public override Task ReadAsBooleanAsync(CancellationToken cancellationToken = default(CancellationToken)) + public override Task 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 []. This result will be null at the end of an array. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - public override Task ReadAsBytesAsync(CancellationToken cancellationToken = default(CancellationToken)) + public override Task ReadAsBytesAsync(CancellationToken cancellationToken = default) { return _safeAsync ? DoReadAsBytesAsync(cancellationToken) : base.ReadAsBytesAsync(cancellationToken); } @@ -1663,7 +1663,7 @@ namespace Newtonsoft.Json /// property returns the of . This result will be null at the end of an array. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - public override Task ReadAsDateTimeAsync(CancellationToken cancellationToken = default(CancellationToken)) + public override Task ReadAsDateTimeAsync(CancellationToken cancellationToken = default) { return _safeAsync ? DoReadAsDateTimeAsync(cancellationToken) : base.ReadAsDateTimeAsync(cancellationToken); } @@ -1681,7 +1681,7 @@ namespace Newtonsoft.Json /// property returns the of . This result will be null at the end of an array. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - public override Task ReadAsDateTimeOffsetAsync(CancellationToken cancellationToken = default(CancellationToken)) + public override Task ReadAsDateTimeOffsetAsync(CancellationToken cancellationToken = default) { return _safeAsync ? DoReadAsDateTimeOffsetAsync(cancellationToken) : base.ReadAsDateTimeOffsetAsync(cancellationToken); } @@ -1699,7 +1699,7 @@ namespace Newtonsoft.Json /// property returns the of . This result will be null at the end of an array. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - public override Task ReadAsDecimalAsync(CancellationToken cancellationToken = default(CancellationToken)) + public override Task ReadAsDecimalAsync(CancellationToken cancellationToken = default) { return _safeAsync ? DoReadAsDecimalAsync(cancellationToken) : base.ReadAsDecimalAsync(cancellationToken); } @@ -1717,7 +1717,7 @@ namespace Newtonsoft.Json /// property returns the of . This result will be null at the end of an array. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - public override Task ReadAsDoubleAsync(CancellationToken cancellationToken = default(CancellationToken)) + public override Task ReadAsDoubleAsync(CancellationToken cancellationToken = default) { return _safeAsync ? DoReadAsDoubleAsync(cancellationToken) : base.ReadAsDoubleAsync(cancellationToken); } @@ -1735,7 +1735,7 @@ namespace Newtonsoft.Json /// property returns the of . This result will be null at the end of an array. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - public override Task ReadAsInt32Async(CancellationToken cancellationToken = default(CancellationToken)) + public override Task ReadAsInt32Async(CancellationToken cancellationToken = default) { return _safeAsync ? DoReadAsInt32Async(cancellationToken) : base.ReadAsInt32Async(cancellationToken); } @@ -1753,7 +1753,7 @@ namespace Newtonsoft.Json /// property returns the . This result will be null at the end of an array. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - public override Task ReadAsStringAsync(CancellationToken cancellationToken = default(CancellationToken)) + public override Task ReadAsStringAsync(CancellationToken cancellationToken = default) { return _safeAsync ? DoReadAsStringAsync(cancellationToken) : base.ReadAsStringAsync(cancellationToken); } diff --git a/Src/Newtonsoft.Json/JsonTextWriter.Async.cs b/Src/Newtonsoft.Json/JsonTextWriter.Async.cs index c3b86175..1b98a3f6 100644 --- a/Src/Newtonsoft.Json/JsonTextWriter.Async.cs +++ b/Src/Newtonsoft.Json/JsonTextWriter.Async.cs @@ -51,7 +51,7 @@ namespace Newtonsoft.Json /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. [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 /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. [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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. [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 /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. [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 /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. [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 /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. [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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. [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 /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. [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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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 /// A that represents the asynchronous operation. /// Derived classes must override this method to get asynchronous behaviour. Otherwise it will /// execute synchronously, returning an already-completed task. - 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); } diff --git a/Src/Newtonsoft.Json/JsonTextWriter.cs b/Src/Newtonsoft.Json/JsonTextWriter.cs index 67ee038e..6b7abd91 100644 --- a/Src/Newtonsoft.Json/JsonTextWriter.cs +++ b/Src/Newtonsoft.Json/JsonTextWriter.cs @@ -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 diff --git a/Src/Newtonsoft.Json/JsonValidatingReader.cs b/Src/Newtonsoft.Json/JsonValidatingReader.cs index 2be2f581..34cc3ae6 100644 --- a/Src/Newtonsoft.Json/JsonValidatingReader.cs +++ b/Src/Newtonsoft.Json/JsonValidatingReader.cs @@ -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 schemas = new List(); - - 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 schemas = new List(); + + foreach (JsonSchemaModel schema in CurrentSchemas) { - foreach (KeyValuePair 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 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 schemas = new List(); - - foreach (JsonSchemaModel schema in CurrentSchemas) { - if (!schema.PositionalItemsValidation) + IList schemas = new List(); + + 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; } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/JsonWriter.Async.cs b/Src/Newtonsoft.Json/JsonWriter.Async.cs index fe113736..4a9c0f7d 100644 --- a/Src/Newtonsoft.Json/JsonWriter.Async.cs +++ b/Src/Newtonsoft.Json/JsonWriter.Async.cs @@ -115,7 +115,7 @@ namespace Newtonsoft.Json /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. [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 /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. [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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. [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 /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. [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 /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. [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 /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. [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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. [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 /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. [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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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 /// A that represents the asynchronous operation. /// The default behaviour is to execute synchronously, returning an already-completed task. Derived /// classes can override this behaviour for true asynchronicity. - 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: diff --git a/Src/Newtonsoft.Json/JsonWriter.cs b/Src/Newtonsoft.Json/JsonWriter.cs index 25c68b25..c253585b 100644 --- a/Src/Newtonsoft.Json/JsonWriter.cs +++ b/Src/Newtonsoft.Json/JsonWriter.cs @@ -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(); diff --git a/Src/Newtonsoft.Json/Linq/Extensions.cs b/Src/Newtonsoft.Json/Linq/Extensions.cs index 13fbce03..43b70d4b 100644 --- a/Src/Newtonsoft.Json/Linq/Extensions.cs +++ b/Src/Newtonsoft.Json/Linq/Extensions.cs @@ -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(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) + else if (source is IJEnumerable customEnumerable) { - return (IJEnumerable)source; + return customEnumerable; } else { diff --git a/Src/Newtonsoft.Json/Linq/JArray.Async.cs b/Src/Newtonsoft.Json/Linq/JArray.Async.cs index e747c1a6..ef6bdf52 100644 --- a/Src/Newtonsoft.Json/Linq/JArray.Async.cs +++ b/Src/Newtonsoft.Json/Linq/JArray.Async.cs @@ -60,7 +60,7 @@ namespace Newtonsoft.Json.Linq /// If this is null, default load settings will be used. /// The token to monitor for cancellation requests. The default value is . /// A representing the asynchronous load. The property contains the JSON that was read from the specified . - public new static Task LoadAsync(JsonReader reader, CancellationToken cancellationToken = default(CancellationToken)) + public new static Task LoadAsync(JsonReader reader, CancellationToken cancellationToken = default) { return LoadAsync(reader, null, cancellationToken); } @@ -73,7 +73,7 @@ namespace Newtonsoft.Json.Linq /// If this is null, default load settings will be used. /// The token to monitor for cancellation requests. The default value is . /// A representing the asynchronous load. The property contains the JSON that was read from the specified . - public new static async Task LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default(CancellationToken)) + public new static async Task LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default) { if (reader.TokenType == JsonToken.None) { diff --git a/Src/Newtonsoft.Json/Linq/JConstructor.Async.cs b/Src/Newtonsoft.Json/Linq/JConstructor.Async.cs index ea4e5e86..d24b81f8 100644 --- a/Src/Newtonsoft.Json/Linq/JConstructor.Async.cs +++ b/Src/Newtonsoft.Json/Linq/JConstructor.Async.cs @@ -61,7 +61,7 @@ namespace Newtonsoft.Json.Linq /// /// A that represents the asynchronous load. The /// property returns a that contains the JSON that was read from the specified . - public new static Task LoadAsync(JsonReader reader, CancellationToken cancellationToken = default(CancellationToken)) + public new static Task LoadAsync(JsonReader reader, CancellationToken cancellationToken = default) { return LoadAsync(reader, null, cancellationToken); } @@ -76,7 +76,7 @@ namespace Newtonsoft.Json.Linq /// /// A that represents the asynchronous load. The /// property returns a that contains the JSON that was read from the specified . - public new static async Task LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default(CancellationToken)) + public new static async Task LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default) { if (reader.TokenType == JsonToken.None) { diff --git a/Src/Newtonsoft.Json/Linq/JConstructor.cs b/Src/Newtonsoft.Json/Linq/JConstructor.cs index 03b3f550..759008fd 100644 --- a/Src/Newtonsoft.Json/Linq/JConstructor.cs +++ b/Src/Newtonsoft.Json/Linq/JConstructor.cs @@ -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); } } diff --git a/Src/Newtonsoft.Json/Linq/JContainer.Async.cs b/Src/Newtonsoft.Json/Linq/JContainer.Async.cs index 004a9ec0..ec235c14 100644 --- a/Src/Newtonsoft.Json/Linq/JContainer.Async.cs +++ b/Src/Newtonsoft.Json/Linq/JContainer.Async.cs @@ -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) { diff --git a/Src/Newtonsoft.Json/Linq/JContainer.cs b/Src/Newtonsoft.Json/Linq/JContainer.cs index dff7f4ba..d586aaf0 100644 --- a/Src/Newtonsoft.Json/Linq/JContainer.cs +++ b/Src/Newtonsoft.Json/Linq/JContainer.cs @@ -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; diff --git a/Src/Newtonsoft.Json/Linq/JObject.Async.cs b/Src/Newtonsoft.Json/Linq/JObject.Async.cs index 8dba9055..21eb02b7 100644 --- a/Src/Newtonsoft.Json/Linq/JObject.Async.cs +++ b/Src/Newtonsoft.Json/Linq/JObject.Async.cs @@ -82,7 +82,7 @@ namespace Newtonsoft.Json.Linq /// /// A that represents the asynchronous load. The /// property returns a that contains the JSON that was read from the specified . - public new static Task LoadAsync(JsonReader reader, CancellationToken cancellationToken = default(CancellationToken)) + public new static Task LoadAsync(JsonReader reader, CancellationToken cancellationToken = default) { return LoadAsync(reader, null, cancellationToken); } @@ -97,7 +97,7 @@ namespace Newtonsoft.Json.Linq /// /// A that represents the asynchronous load. The /// property returns a that contains the JSON that was read from the specified . - public new static async Task LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default(CancellationToken)) + public new static async Task LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default) { ValidationUtils.ArgumentNotNull(reader, nameof(reader)); diff --git a/Src/Newtonsoft.Json/Linq/JProperty.Async.cs b/Src/Newtonsoft.Json/Linq/JProperty.Async.cs index bd5cfb7d..9083a985 100644 --- a/Src/Newtonsoft.Json/Linq/JProperty.Async.cs +++ b/Src/Newtonsoft.Json/Linq/JProperty.Async.cs @@ -74,7 +74,7 @@ namespace Newtonsoft.Json.Linq /// The token to monitor for cancellation requests. The default value is . /// A representing the asynchronous creation. The /// property returns a that contains the JSON that was read from the specified . - public new static Task LoadAsync(JsonReader reader, CancellationToken cancellationToken = default(CancellationToken)) + public new static Task LoadAsync(JsonReader reader, CancellationToken cancellationToken = default) { return LoadAsync(reader, null, cancellationToken); } @@ -88,7 +88,7 @@ namespace Newtonsoft.Json.Linq /// The token to monitor for cancellation requests. The default value is . /// A representing the asynchronous creation. The /// property returns a that contains the JSON that was read from the specified . - public new static async Task LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default(CancellationToken)) + public new static async Task LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default) { if (reader.TokenType == JsonToken.None) { diff --git a/Src/Newtonsoft.Json/Linq/JRaw.Async.cs b/Src/Newtonsoft.Json/Linq/JRaw.Async.cs index 8f24d305..efb4f618 100644 --- a/Src/Newtonsoft.Json/Linq/JRaw.Async.cs +++ b/Src/Newtonsoft.Json/Linq/JRaw.Async.cs @@ -41,7 +41,7 @@ namespace Newtonsoft.Json.Linq /// The token to monitor for cancellation requests. The default value is . /// A representing the asynchronous creation. The /// property returns an instance of with the content of the reader's current token. - public static async Task CreateAsync(JsonReader reader, CancellationToken cancellationToken = default(CancellationToken)) + public static async Task CreateAsync(JsonReader reader, CancellationToken cancellationToken = default) { using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture)) using (JsonTextWriter jsonWriter = new JsonTextWriter(sw)) diff --git a/Src/Newtonsoft.Json/Linq/JToken.Async.cs b/Src/Newtonsoft.Json/Linq/JToken.Async.cs index 5833879d..1d89e0fd 100644 --- a/Src/Newtonsoft.Json/Linq/JToken.Async.cs +++ b/Src/Newtonsoft.Json/Linq/JToken.Async.cs @@ -55,7 +55,7 @@ namespace Newtonsoft.Json.Linq /// A that represents the asynchronous write operation. public Task WriteToAsync(JsonWriter writer, params JsonConverter[] converters) { - return WriteToAsync(writer, default(CancellationToken), converters); + return WriteToAsync(writer, default, converters); } /// @@ -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. /// - public static Task ReadFromAsync(JsonReader reader, CancellationToken cancellationToken = default(CancellationToken)) + public static Task 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. /// - public static async Task ReadFromAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default(CancellationToken)) + public static async Task 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. /// - public static Task LoadAsync(JsonReader reader, CancellationToken cancellationToken = default(CancellationToken)) + public static Task 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. /// - public static Task LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default(CancellationToken)) + public static Task LoadAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default) { return ReadFromAsync(reader, settings, cancellationToken); } diff --git a/Src/Newtonsoft.Json/Linq/JToken.cs b/Src/Newtonsoft.Json/Linq/JToken.cs index 0ba60d6e..05f641c1 100644 --- a/Src/Newtonsoft.Json/Linq/JToken.cs +++ b/Src/Newtonsoft.Json/Linq/JToken.cs @@ -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(token); + return token == null ? default : Extensions.Convert(token); } /// @@ -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; } /// diff --git a/Src/Newtonsoft.Json/Linq/JTokenReader.cs b/Src/Newtonsoft.Json/Linq/JTokenReader.cs index c901d603..e0db7579 100644 --- a/Src/Newtonsoft.Json/Linq/JTokenReader.cs +++ b/Src/Newtonsoft.Json/Linq/JTokenReader.cs @@ -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: diff --git a/Src/Newtonsoft.Json/Linq/JValue.cs b/Src/Newtonsoft.Json/Linq/JValue.cs index 0232d2ab..85e2473f 100644 --- a/Src/Newtonsoft.Json/Linq/JValue.cs +++ b/Src/Newtonsoft.Json/Linq/JValue.cs @@ -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) diff --git a/Src/Newtonsoft.Json/Schema/JsonSchemaBuilder.cs b/Src/Newtonsoft.Json/Schema/JsonSchemaBuilder.cs index 206aa6ef..310ef70a 100644 --- a/Src/Newtonsoft.Json/Schema/JsonSchemaBuilder.cs +++ b/Src/Newtonsoft.Json/Schema/JsonSchemaBuilder.cs @@ -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)); } diff --git a/Src/Newtonsoft.Json/Schema/JsonSchemaModelBuilder.cs b/Src/Newtonsoft.Json/Schema/JsonSchemaModelBuilder.cs index 51cae457..648206a7 100644 --- a/Src/Newtonsoft.Json/Schema/JsonSchemaModelBuilder.cs +++ b/Src/Newtonsoft.Json/Schema/JsonSchemaModelBuilder.cs @@ -126,8 +126,7 @@ namespace Newtonsoft.Json.Schema public void AddProperty(IDictionary 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; } diff --git a/Src/Newtonsoft.Json/Serialization/CamelCasePropertyNamesContractResolver.cs b/Src/Newtonsoft.Json/Serialization/CamelCasePropertyNamesContractResolver.cs index ec2c0c91..8f453621 100644 --- a/Src/Newtonsoft.Json/Serialization/CamelCasePropertyNamesContractResolver.cs +++ b/Src/Newtonsoft.Json/Serialization/CamelCasePropertyNamesContractResolver.cs @@ -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 cache = _contractCache; - if (cache == null || !cache.TryGetValue(key, out contract)) + if (cache == null || !cache.TryGetValue(key, out JsonContract contract)) { contract = CreateContract(type); diff --git a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs index f11a7be8..a0da7ff4 100644 --- a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs +++ b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs @@ -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 /// @@ -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") { diff --git a/Src/Newtonsoft.Json/Serialization/JsonFormatterConverter.cs b/Src/Newtonsoft.Json/Serialization/JsonFormatterConverter.cs index 8be45fb9..52f61ae2 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonFormatterConverter.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonFormatterConverter.cs @@ -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); diff --git a/Src/Newtonsoft.Json/Serialization/JsonPropertyCollection.cs b/Src/Newtonsoft.Json/Serialization/JsonPropertyCollection.cs index 312acf66..9bb5a5cf 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonPropertyCollection.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonPropertyCollection.cs @@ -144,7 +144,7 @@ namespace Newtonsoft.Json.Serialization { if (Dictionary == null) { - item = default(JsonProperty); + item = default; return false; } diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs index c4d588ae..38993e78 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs @@ -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; } diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs index 46d3f015..890daf9e 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs @@ -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) diff --git a/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs b/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs index a98ea366..9025c94b 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs @@ -388,8 +388,7 @@ namespace Newtonsoft.Json.Serialization // no inheritance return (ReflectionUtils.GetAttribute(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(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(object provider) where T : Attribute { - Type type = provider as Type; - if (type != null) + if (provider is Type type) { return GetAttribute(type); } - MemberInfo memberInfo = provider as MemberInfo; - if (memberInfo != null) + if (provider is MemberInfo memberInfo) { return GetAttribute(memberInfo); } @@ -451,7 +447,7 @@ namespace Newtonsoft.Json.Serialization #if HAVE_SECURITY_SAFE_CRITICAL_ATTRIBUTE [SecuritySafeCritical] #endif - get + get { if (_dynamicCodeGeneration == null) { diff --git a/Src/Newtonsoft.Json/Serialization/TraceJsonReader.cs b/Src/Newtonsoft.Json/Serialization/TraceJsonReader.cs index f0817dfd..5dbbd5de 100644 --- a/Src/Newtonsoft.Json/Serialization/TraceJsonReader.cs +++ b/Src/Newtonsoft.Json/Serialization/TraceJsonReader.cs @@ -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; } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Utilities/AsyncUtils.cs b/Src/Newtonsoft.Json/Utilities/AsyncUtils.cs index c0a7a90e..49cbad97 100644 --- a/Src/Newtonsoft.Json/Utilities/AsyncUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/AsyncUtils.cs @@ -61,7 +61,7 @@ namespace Newtonsoft.Json.Utilities public static Task FromCanceled(this CancellationToken cancellationToken) { Debug.Assert(cancellationToken.IsCancellationRequested); - return new Task(() => default(T), cancellationToken); + return new Task(() => default, cancellationToken); } // Task.Delay(0) is optimised as a cached task within the framework, and indeed diff --git a/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs b/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs index cf2f0c12..0e3f885c 100644 --- a/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs @@ -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) diff --git a/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs b/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs index 24e076dc..34e65a34 100644 --- a/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs @@ -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; } } diff --git a/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs b/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs index 96a80a35..78cea5e2 100644 --- a/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs +++ b/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs @@ -161,7 +161,7 @@ namespace Newtonsoft.Json.Utilities { if (!_dictionary.Contains(key)) { - value = default(TValue); + value = default; return false; } else diff --git a/Src/Newtonsoft.Json/Utilities/EnumUtils.cs b/Src/Newtonsoft.Json/Utilities/EnumUtils.cs index 9b249858..d9f4c4da 100644 --- a/Src/Newtonsoft.Json/Utilities/EnumUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/EnumUtils.cs @@ -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; diff --git a/Src/Newtonsoft.Json/Utilities/ExpressionReflectionDelegateFactory.cs b/Src/Newtonsoft.Json/Utilities/ExpressionReflectionDelegateFactory.cs index 33d800cb..6d6f8d7b 100644 --- a/Src/Newtonsoft.Json/Utilities/ExpressionReflectionDelegateFactory.cs +++ b/Src/Newtonsoft.Json/Utilities/ExpressionReflectionDelegateFactory.cs @@ -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)) { diff --git a/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs b/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs index a50fc631..adde262f 100644 --- a/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs @@ -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) diff --git a/Src/Newtonsoft.Json/Utilities/LateBoundReflectionDelegateFactory.cs b/Src/Newtonsoft.Json/Utilities/LateBoundReflectionDelegateFactory.cs index ddccd316..a82150c1 100644 --- a/Src/Newtonsoft.Json/Utilities/LateBoundReflectionDelegateFactory.cs +++ b/Src/Newtonsoft.Json/Utilities/LateBoundReflectionDelegateFactory.cs @@ -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); } diff --git a/Src/Newtonsoft.Json/Utilities/MiscellaneousUtils.cs b/Src/Newtonsoft.Json/Utilities/MiscellaneousUtils.cs index 5c40ae8a..399e500d 100644 --- a/Src/Newtonsoft.Json/Utilities/MiscellaneousUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/MiscellaneousUtils.cs @@ -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; diff --git a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs index c86995f5..5971ead3 100644 --- a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs @@ -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) diff --git a/Src/Newtonsoft.Json/Utilities/TypeExtensions.cs b/Src/Newtonsoft.Json/Utilities/TypeExtensions.cs index 86b62a16..64608081 100644 --- a/Src/Newtonsoft.Json/Utilities/TypeExtensions.cs +++ b/Src/Newtonsoft.Json/Utilities/TypeExtensions.cs @@ -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)