diff --git a/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs b/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs index 1f3c0aa3cc..49dd41f91d 100644 --- a/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs +++ b/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs @@ -49,19 +49,15 @@ public BsonBinaryWriter(BinaryWriter writer) _writer = writer; } - public void Flush() - { - _writer.Flush(); - } + public void Flush() => _writer.Flush(); - public void Close() - { + public void Close() => #if HAVE_STREAM_READER_WRITER_CLOSE _writer.Close(); #else _writer.Dispose(); #endif - } + public void WriteToken(BsonToken t) { diff --git a/Src/Newtonsoft.Json/Bson/BsonReader.cs b/Src/Newtonsoft.Json/Bson/BsonReader.cs index 45569331d8..114896854e 100644 --- a/Src/Newtonsoft.Json/Bson/BsonReader.cs +++ b/Src/Newtonsoft.Json/Bson/BsonReader.cs @@ -81,10 +81,7 @@ private class ContainerContext public int Length; public int Position; - public ContainerContext(BsonType type) - { - Type = type; - } + public ContainerContext(BsonType type) => Type = type; } /// diff --git a/Src/Newtonsoft.Json/Bson/BsonToken.cs b/Src/Newtonsoft.Json/Bson/BsonToken.cs index 202bca6e54..b639e564f5 100644 --- a/Src/Newtonsoft.Json/Bson/BsonToken.cs +++ b/Src/Newtonsoft.Json/Bson/BsonToken.cs @@ -49,15 +49,9 @@ public void Add(string name, BsonToken token) public override BsonType Type => BsonType.Object; - public IEnumerator GetEnumerator() - { - return _children.GetEnumerator(); - } + public IEnumerator GetEnumerator() => _children.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } internal class BsonArray : BsonToken, IEnumerable @@ -73,14 +67,9 @@ public void Add(BsonToken token) public override BsonType Type => BsonType.Array; public IEnumerator GetEnumerator() - { - return _children.GetEnumerator(); - } + => _children.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } internal class BsonEmpty : BsonToken @@ -88,10 +77,7 @@ internal class BsonEmpty : BsonToken public static readonly BsonToken Null = new BsonEmpty(BsonType.Null); public static readonly BsonToken Undefined = new BsonEmpty(BsonType.Undefined); - private BsonEmpty(BsonType type) - { - Type = type; - } + private BsonEmpty(BsonType type) => Type = type; public override BsonType Type { get; } } @@ -129,10 +115,7 @@ internal class BsonString : BsonValue public bool IncludeLength { get; } public BsonString(object value, bool includeLength) - : base(value, BsonType.String) - { - IncludeLength = includeLength; - } + : base(value, BsonType.String) => IncludeLength = includeLength; } internal class BsonBinary : BsonValue @@ -140,10 +123,7 @@ internal class BsonBinary : BsonValue public BsonBinaryType BinaryType { get; set; } public BsonBinary(byte[] value, BsonBinaryType binaryType) - : base(value, BsonType.Binary) - { - BinaryType = binaryType; - } + : base(value, BsonType.Binary) => BinaryType = binaryType; } internal class BsonRegex : BsonToken diff --git a/Src/Newtonsoft.Json/Bson/BsonWriter.cs b/Src/Newtonsoft.Json/Bson/BsonWriter.cs index 47d34fa3be..1a42a65a0e 100644 --- a/Src/Newtonsoft.Json/Bson/BsonWriter.cs +++ b/Src/Newtonsoft.Json/Bson/BsonWriter.cs @@ -85,10 +85,7 @@ public BsonWriter(BinaryWriter writer) /// /// Flushes whatever is in the buffer to the underlying and also flushes the underlying stream. /// - public override void Flush() - { - _writer.Flush(); - } + public override void Flush() => _writer.Flush(); /// /// Writes the end. @@ -193,15 +190,9 @@ private void AddParent(BsonToken container) _parent = container; } - private void RemoveParent() - { - _parent = _parent.Parent; - } + private void RemoveParent() => _parent = _parent.Parent; - private void AddValue(object value, BsonType type) - { - AddToken(new BsonValue(value, type)); - } + private void AddValue(object value, BsonType type) => AddToken(new BsonValue(value, type)); internal void AddToken(BsonToken token) { diff --git a/Src/Newtonsoft.Json/Converters/BsonObjectIdConverter.cs b/Src/Newtonsoft.Json/Converters/BsonObjectIdConverter.cs index 5f918de254..7fbc742151 100644 --- a/Src/Newtonsoft.Json/Converters/BsonObjectIdConverter.cs +++ b/Src/Newtonsoft.Json/Converters/BsonObjectIdConverter.cs @@ -85,9 +85,6 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist /// /// true if this instance can convert the specified object type; otherwise, false. /// - public override bool CanConvert(Type objectType) - { - return (objectType == typeof(BsonObjectId)); - } + public override bool CanConvert(Type objectType) => (objectType == typeof(BsonObjectId)); } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Converters/CustomCreationConverter.cs b/Src/Newtonsoft.Json/Converters/CustomCreationConverter.cs index f693ce574a..cc2c6aa053 100644 --- a/Src/Newtonsoft.Json/Converters/CustomCreationConverter.cs +++ b/Src/Newtonsoft.Json/Converters/CustomCreationConverter.cs @@ -85,10 +85,7 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer /// /// true if this instance can convert the specified object type; otherwise, false. /// - public override bool CanConvert(Type objectType) - { - return typeof(T).IsAssignableFrom(objectType); - } + public override bool CanConvert(Type objectType) => typeof(T).IsAssignableFrom(objectType); /// /// Gets a value indicating whether this can write JSON. diff --git a/Src/Newtonsoft.Json/Converters/DataSetConverter.cs b/Src/Newtonsoft.Json/Converters/DataSetConverter.cs index 214728e670..56298c05c6 100644 --- a/Src/Newtonsoft.Json/Converters/DataSetConverter.cs +++ b/Src/Newtonsoft.Json/Converters/DataSetConverter.cs @@ -115,10 +115,7 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer /// /// true if this instance can convert the specified value type; otherwise, false. /// - public override bool CanConvert(Type valueType) - { - return typeof(DataSet).IsAssignableFrom(valueType); - } + public override bool CanConvert(Type valueType) => typeof(DataSet).IsAssignableFrom(valueType); } } diff --git a/Src/Newtonsoft.Json/Converters/DataTableConverter.cs b/Src/Newtonsoft.Json/Converters/DataTableConverter.cs index 1a32e51213..288b1891ee 100644 --- a/Src/Newtonsoft.Json/Converters/DataTableConverter.cs +++ b/Src/Newtonsoft.Json/Converters/DataTableConverter.cs @@ -244,10 +244,7 @@ private static Type GetColumnDataType(JsonReader reader) /// /// true if this instance can convert the specified value type; otherwise, false. /// - public override bool CanConvert(Type valueType) - { - return typeof(DataTable).IsAssignableFrom(valueType); - } + public override bool CanConvert(Type valueType) => typeof(DataTable).IsAssignableFrom(valueType); } } diff --git a/Src/Newtonsoft.Json/Converters/EntityKeyMemberConverter.cs b/Src/Newtonsoft.Json/Converters/EntityKeyMemberConverter.cs index 757c8fac65..5eb9f229d9 100644 --- a/Src/Newtonsoft.Json/Converters/EntityKeyMemberConverter.cs +++ b/Src/Newtonsoft.Json/Converters/EntityKeyMemberConverter.cs @@ -155,10 +155,8 @@ private static void EnsureReflectionObject(Type objectType) /// /// true if this instance can convert the specified object type; otherwise, false. /// - public override bool CanConvert(Type objectType) - { - return objectType.AssignableToTypeName(EntityKeyMemberFullTypeName, false); - } + public override bool CanConvert(Type objectType) + => objectType.AssignableToTypeName(EntityKeyMemberFullTypeName, false); } } diff --git a/Src/Newtonsoft.Json/Converters/ExpandoObjectConverter.cs b/Src/Newtonsoft.Json/Converters/ExpandoObjectConverter.cs index 5a674b8c16..e7c06e2da7 100644 --- a/Src/Newtonsoft.Json/Converters/ExpandoObjectConverter.cs +++ b/Src/Newtonsoft.Json/Converters/ExpandoObjectConverter.cs @@ -59,10 +59,8 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer /// The existing value of object being read. /// The calling serializer. /// The object value. - public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) - { - return ReadValue(reader); - } + public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) + => ReadValue(reader); private object? ReadValue(JsonReader reader) { @@ -147,10 +145,7 @@ private object ReadObject(JsonReader reader) /// /// true if this instance can convert the specified object type; otherwise, false. /// - public override bool CanConvert(Type objectType) - { - return (objectType == typeof(ExpandoObject)); - } + public override bool CanConvert(Type objectType) => (objectType == typeof(ExpandoObject)); /// /// Gets a value indicating whether this can write JSON. diff --git a/Src/Newtonsoft.Json/Converters/RegexConverter.cs b/Src/Newtonsoft.Json/Converters/RegexConverter.cs index 13db1bb574..8f4a56da85 100644 --- a/Src/Newtonsoft.Json/Converters/RegexConverter.cs +++ b/Src/Newtonsoft.Json/Converters/RegexConverter.cs @@ -69,10 +69,7 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer } } - private bool HasFlag(RegexOptions options, RegexOptions flag) - { - return ((options & flag) == flag); - } + private bool HasFlag(RegexOptions options, RegexOptions flag) => ((options & flag) == flag); #pragma warning disable 618 private void WriteBson(BsonWriter writer, Regex regex) @@ -221,15 +218,9 @@ private Regex ReadRegexObject(JsonReader reader, JsonSerializer serializer) /// /// true if this instance can convert the specified object type; otherwise, false. /// - public override bool CanConvert(Type objectType) - { - return objectType.Name == nameof(Regex) && IsRegex(objectType); - } + public override bool CanConvert(Type objectType) => objectType.Name == nameof(Regex) && IsRegex(objectType); [MethodImpl(MethodImplOptions.NoInlining)] - private bool IsRegex(Type objectType) - { - return (objectType == typeof(Regex)); - } + private bool IsRegex(Type objectType) => (objectType == typeof(Regex)); } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Converters/UnixDateTimeConverter.cs b/Src/Newtonsoft.Json/Converters/UnixDateTimeConverter.cs index 7d0700e0cb..b7c9a8a054 100644 --- a/Src/Newtonsoft.Json/Converters/UnixDateTimeConverter.cs +++ b/Src/Newtonsoft.Json/Converters/UnixDateTimeConverter.cs @@ -62,10 +62,7 @@ public UnixDateTimeConverter() : this(false) /// false to throw an exception when a date being converted to or from JSON /// occurred before Unix epoch. The default value is false. /// - public UnixDateTimeConverter(bool allowPreEpoch) - { - AllowPreEpoch = allowPreEpoch; - } + public UnixDateTimeConverter(bool allowPreEpoch) => AllowPreEpoch = allowPreEpoch; /// /// Writes the JSON representation of the object. diff --git a/Src/Newtonsoft.Json/Converters/VersionConverter.cs b/Src/Newtonsoft.Json/Converters/VersionConverter.cs index e0cded265f..444ab05a72 100644 --- a/Src/Newtonsoft.Json/Converters/VersionConverter.cs +++ b/Src/Newtonsoft.Json/Converters/VersionConverter.cs @@ -98,9 +98,6 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer /// /// true if this instance can convert the specified object type; otherwise, false. /// - public override bool CanConvert(Type objectType) - { - return objectType == typeof(Version); - } + public override bool CanConvert(Type objectType) => objectType == typeof(Version); } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs index 12bde5157d..94ec93601c 100644 --- a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs +++ b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs @@ -2215,18 +2215,12 @@ public override bool CanConvert(Type valueType) #if HAVE_XLINQ [MethodImpl(MethodImplOptions.NoInlining)] - private bool IsXObject(Type valueType) - { - return typeof(XObject).IsAssignableFrom(valueType); - } + private bool IsXObject(Type valueType) => typeof(XObject).IsAssignableFrom(valueType); #endif #if HAVE_XML_DOCUMENT [MethodImpl(MethodImplOptions.NoInlining)] - private bool IsXmlNode(Type valueType) - { - return typeof(XmlNode).IsAssignableFrom(valueType); - } + private bool IsXmlNode(Type valueType) => typeof(XmlNode).IsAssignableFrom(valueType); #endif } } diff --git a/Src/Newtonsoft.Json/DefaultJsonNameTable.cs b/Src/Newtonsoft.Json/DefaultJsonNameTable.cs index 659eefab74..4cba6f5d9a 100644 --- a/Src/Newtonsoft.Json/DefaultJsonNameTable.cs +++ b/Src/Newtonsoft.Json/DefaultJsonNameTable.cs @@ -40,18 +40,12 @@ public class DefaultJsonNameTable : JsonNameTable private Entry[] _entries; private int _mask = 31; - static DefaultJsonNameTable() - { - HashCodeRandomizer = Environment.TickCount; - } + static DefaultJsonNameTable() => HashCodeRandomizer = Environment.TickCount; /// /// Initializes a new instance of the class. /// - public DefaultJsonNameTable() - { - _entries = new Entry[_mask + 1]; - } + public DefaultJsonNameTable() => _entries = new Entry[_mask + 1]; /// /// Gets a string containing the same characters as the specified range of characters in the given array. diff --git a/Src/Newtonsoft.Json/JsonArrayAttribute.cs b/Src/Newtonsoft.Json/JsonArrayAttribute.cs index 96221a7a9d..6a37c23649 100644 --- a/Src/Newtonsoft.Json/JsonArrayAttribute.cs +++ b/Src/Newtonsoft.Json/JsonArrayAttribute.cs @@ -56,10 +56,7 @@ public JsonArrayAttribute() /// Initializes a new instance of the class with a flag indicating whether the array can contain null items. /// /// A flag indicating whether the array can contain null items. - public JsonArrayAttribute(bool allowNullItems) - { - _allowNullItems = allowNullItems; - } + public JsonArrayAttribute(bool allowNullItems) => _allowNullItems = allowNullItems; /// /// Initializes a new instance of the class with the specified container Id. diff --git a/Src/Newtonsoft.Json/JsonConvert.cs b/Src/Newtonsoft.Json/JsonConvert.cs index 1fa3f21955..f601ea480a 100644 --- a/Src/Newtonsoft.Json/JsonConvert.cs +++ b/Src/Newtonsoft.Json/JsonConvert.cs @@ -101,10 +101,8 @@ public static class JsonConvert /// /// The value to convert. /// A JSON string representation of the . - public static string ToString(DateTime value) - { - return ToString(value, DateFormatHandling.IsoDateFormat, DateTimeZoneHandling.RoundtripKind); - } + public static string ToString(DateTime value) + => ToString(value, DateFormatHandling.IsoDateFormat, DateTimeZoneHandling.RoundtripKind); /// /// Converts the to its JSON string representation using the specified. @@ -132,10 +130,7 @@ public static string ToString(DateTime value, DateFormatHandling format, DateTim /// /// The value to convert. /// A JSON string representation of the . - public static string ToString(DateTimeOffset value) - { - return ToString(value, DateFormatHandling.IsoDateFormat); - } + public static string ToString(DateTimeOffset value) => ToString(value, DateFormatHandling.IsoDateFormat); /// /// Converts the to its JSON string representation using the specified. @@ -160,50 +155,35 @@ public static string ToString(DateTimeOffset value, DateFormatHandling format) /// /// The value to convert. /// A JSON string representation of the . - public static string ToString(bool value) - { - return (value) ? True : False; - } + public static string ToString(bool value) => (value) ? True : False; /// /// Converts the to its JSON string representation. /// /// The value to convert. /// A JSON string representation of the . - public static string ToString(char value) - { - return ToString(char.ToString(value)); - } + public static string ToString(char value) => ToString(char.ToString(value)); /// /// Converts the to its JSON string representation. /// /// The value to convert. /// A JSON string representation of the . - public static string ToString(Enum value) - { - return value.ToString("D"); - } + public static string ToString(Enum value) => value.ToString("D"); /// /// Converts the to its JSON string representation. /// /// The value to convert. /// A JSON string representation of the . - public static string ToString(int value) - { - return value.ToString(null, CultureInfo.InvariantCulture); - } + public static string ToString(int value) => value.ToString(null, CultureInfo.InvariantCulture); /// /// Converts the to its JSON string representation. /// /// The value to convert. /// A JSON string representation of the . - public static string ToString(short value) - { - return value.ToString(null, CultureInfo.InvariantCulture); - } + public static string ToString(short value) => value.ToString(null, CultureInfo.InvariantCulture); /// /// Converts the to its JSON string representation. @@ -211,10 +191,7 @@ public static string ToString(short value) /// The value to convert. /// A JSON string representation of the . [CLSCompliant(false)] - public static string ToString(ushort value) - { - return value.ToString(null, CultureInfo.InvariantCulture); - } + public static string ToString(ushort value) => value.ToString(null, CultureInfo.InvariantCulture); /// /// Converts the to its JSON string representation. @@ -222,26 +199,17 @@ public static string ToString(ushort value) /// The value to convert. /// A JSON string representation of the . [CLSCompliant(false)] - public static string ToString(uint value) - { - return value.ToString(null, CultureInfo.InvariantCulture); - } + public static string ToString(uint value) => value.ToString(null, CultureInfo.InvariantCulture); /// /// Converts the to its JSON string representation. /// /// The value to convert. /// A JSON string representation of the . - public static string ToString(long value) - { - return value.ToString(null, CultureInfo.InvariantCulture); - } + public static string ToString(long value) => value.ToString(null, CultureInfo.InvariantCulture); #if HAVE_BIG_INTEGER - private static string ToStringInternal(BigInteger value) - { - return value.ToString(null, CultureInfo.InvariantCulture); - } + private static string ToStringInternal(BigInteger value) => value.ToString(null, CultureInfo.InvariantCulture); #endif /// @@ -250,25 +218,17 @@ private static string ToStringInternal(BigInteger value) /// The value to convert. /// A JSON string representation of the . [CLSCompliant(false)] - public static string ToString(ulong value) - { - return value.ToString(null, CultureInfo.InvariantCulture); - } + public static string ToString(ulong value) => value.ToString(null, CultureInfo.InvariantCulture); /// /// Converts the to its JSON string representation. /// /// The value to convert. /// A JSON string representation of the . - public static string ToString(float value) - { - return EnsureDecimalPlace(value, value.ToString("R", CultureInfo.InvariantCulture)); - } + public static string ToString(float value) => EnsureDecimalPlace(value, value.ToString("R", CultureInfo.InvariantCulture)); - internal static string ToString(float value, FloatFormatHandling floatFormatHandling, char quoteChar, bool nullable) - { - return EnsureFloatFormat(value, EnsureDecimalPlace(value, value.ToString("R", CultureInfo.InvariantCulture)), floatFormatHandling, quoteChar, nullable); - } + internal static string ToString(float value, FloatFormatHandling floatFormatHandling, char quoteChar, bool nullable) + => EnsureFloatFormat(value, EnsureDecimalPlace(value, value.ToString("R", CultureInfo.InvariantCulture)), floatFormatHandling, quoteChar, nullable); private static string EnsureFloatFormat(double value, string text, FloatFormatHandling floatFormatHandling, char quoteChar, bool nullable) { @@ -290,15 +250,10 @@ private static string EnsureFloatFormat(double value, string text, FloatFormatHa /// /// The value to convert. /// A JSON string representation of the . - public static string ToString(double value) - { - return EnsureDecimalPlace(value, value.ToString("R", CultureInfo.InvariantCulture)); - } + public static string ToString(double value) => EnsureDecimalPlace(value, value.ToString("R", CultureInfo.InvariantCulture)); - internal static string ToString(double value, FloatFormatHandling floatFormatHandling, char quoteChar, bool nullable) - { - return EnsureFloatFormat(value, EnsureDecimalPlace(value, value.ToString("R", CultureInfo.InvariantCulture)), floatFormatHandling, quoteChar, nullable); - } + internal static string ToString(double value, FloatFormatHandling floatFormatHandling, char quoteChar, bool nullable) + => EnsureFloatFormat(value, EnsureDecimalPlace(value, value.ToString("R", CultureInfo.InvariantCulture)), floatFormatHandling, quoteChar, nullable); private static string EnsureDecimalPlace(double value, string text) { @@ -325,10 +280,7 @@ private static string EnsureDecimalPlace(string text) /// /// The value to convert. /// A JSON string representation of the . - public static string ToString(byte value) - { - return value.ToString(null, CultureInfo.InvariantCulture); - } + public static string ToString(byte value) => value.ToString(null, CultureInfo.InvariantCulture); /// /// Converts the to its JSON string representation. @@ -336,30 +288,21 @@ public static string ToString(byte value) /// The value to convert. /// A JSON string representation of the . [CLSCompliant(false)] - public static string ToString(sbyte value) - { - return value.ToString(null, CultureInfo.InvariantCulture); - } + public static string ToString(sbyte value) => value.ToString(null, CultureInfo.InvariantCulture); /// /// Converts the to its JSON string representation. /// /// The value to convert. /// A JSON string representation of the . - public static string ToString(decimal value) - { - return EnsureDecimalPlace(value.ToString(null, CultureInfo.InvariantCulture)); - } + public static string ToString(decimal value) => EnsureDecimalPlace(value.ToString(null, CultureInfo.InvariantCulture)); /// /// Converts the to its JSON string representation. /// /// The value to convert. /// A JSON string representation of the . - public static string ToString(Guid value) - { - return ToString(value, '"'); - } + public static string ToString(Guid value) => ToString(value, '"'); internal static string ToString(Guid value, char quoteChar) { @@ -381,15 +324,9 @@ internal static string ToString(Guid value, char quoteChar) /// /// The value to convert. /// A JSON string representation of the . - public static string ToString(TimeSpan value) - { - return ToString(value, '"'); - } + public static string ToString(TimeSpan value) => ToString(value, '"'); - internal static string ToString(TimeSpan value, char quoteChar) - { - return ToString(value.ToString(), quoteChar); - } + internal static string ToString(TimeSpan value, char quoteChar) => ToString(value.ToString(), quoteChar); /// /// Converts the to its JSON string representation. @@ -406,20 +343,14 @@ public static string ToString(Uri? value) return ToString(value, '"'); } - internal static string ToString(Uri value, char quoteChar) - { - return ToString(value.OriginalString, quoteChar); - } + internal static string ToString(Uri value, char quoteChar) => ToString(value.OriginalString, quoteChar); /// /// Converts the to its JSON string representation. /// /// The value to convert. /// A JSON string representation of the . - public static string ToString(string? value) - { - return ToString(value, '"'); - } + public static string ToString(string? value) => ToString(value, '"'); /// /// Converts the to its JSON string representation. @@ -427,10 +358,7 @@ public static string ToString(string? value) /// The value to convert. /// The string delimiter character. /// A JSON string representation of the . - public static string ToString(string? value, char delimiter) - { - return ToString(value, delimiter, StringEscapeHandling.Default); - } + public static string ToString(string? value, char delimiter) => ToString(value, delimiter, StringEscapeHandling.Default); /// /// Converts the to its JSON string representation. diff --git a/Src/Newtonsoft.Json/JsonConverterAttribute.cs b/Src/Newtonsoft.Json/JsonConverterAttribute.cs index a5f071ea76..44d008d7a3 100644 --- a/Src/Newtonsoft.Json/JsonConverterAttribute.cs +++ b/Src/Newtonsoft.Json/JsonConverterAttribute.cs @@ -69,9 +69,6 @@ public JsonConverterAttribute(Type converterType) /// Type of the . /// Parameter list to use when constructing the . Can be null. public JsonConverterAttribute(Type converterType, params object[] converterParameters) - : this(converterType) - { - ConverterParameters = converterParameters; - } + : this(converterType) => ConverterParameters = converterParameters; } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Linq/Extensions.cs b/Src/Newtonsoft.Json/Linq/Extensions.cs index cd333a2f76..c2e798b78b 100644 --- a/Src/Newtonsoft.Json/Linq/Extensions.cs +++ b/Src/Newtonsoft.Json/Linq/Extensions.cs @@ -113,20 +113,15 @@ public static IJEnumerable Properties(this IEnumerable sourc /// An of that contains the source collection. /// The token key. /// An of that contains the values of every token in the source collection with the given key. - public static IJEnumerable Values(this IEnumerable source, object? key) - { - return Values(source, key)!.AsJEnumerable(); - } + public static IJEnumerable Values(this IEnumerable source, object? key) + => Values(source, key)!.AsJEnumerable(); /// /// Returns a collection of child values of every object in the source collection. /// /// An of that contains the source collection. /// An of that contains the values of every token in the source collection. - public static IJEnumerable Values(this IEnumerable source) - { - return source.Values(null); - } + public static IJEnumerable Values(this IEnumerable source) => source.Values(null); /// /// Returns a collection of converted child values of every object in the source collection with the given key. @@ -135,10 +130,7 @@ public static IJEnumerable Values(this IEnumerable source) /// An of that contains the source collection. /// The token key. /// An that contains the converted values of every token in the source collection with the given key. - public static IEnumerable Values(this IEnumerable source, object key) - { - return Values(source, key); - } + public static IEnumerable Values(this IEnumerable source, object key) => Values(source, key); /// /// Returns a collection of converted child values of every object in the source collection. @@ -146,10 +138,7 @@ public static IJEnumerable Values(this IEnumerable source) /// The type to convert the values to. /// An of that contains the source collection. /// An that contains the converted values of every token in the source collection. - public static IEnumerable Values(this IEnumerable source) - { - return Values(source, null); - } + public static IEnumerable Values(this IEnumerable source) => Values(source, null); /// /// Converts the value. @@ -157,10 +146,7 @@ public static IJEnumerable Values(this IEnumerable source) /// The type to convert the value to. /// A cast as a of . /// A converted value. - public static U? Value(this IEnumerable value) - { - return value.Value(); - } + public static U? Value(this IEnumerable value) => value.Value(); /// /// Converts the value. @@ -224,10 +210,8 @@ public static IJEnumerable Values(this IEnumerable source) /// The source collection type. /// An of that contains the source collection. /// An of that contains the values of every token in the source collection. - public static IJEnumerable Children(this IEnumerable source) where T : JToken - { - return Children(source)!.AsJEnumerable(); - } + public static IJEnumerable Children(this IEnumerable source) where T : JToken + => Children(source)!.AsJEnumerable(); /// /// Returns a collection of converted child tokens of every array in the source collection. @@ -306,10 +290,7 @@ public static IJEnumerable Children(this IEnumerable source) where /// /// An of that contains the source collection. /// The input typed as . - public static IJEnumerable AsJEnumerable(this IEnumerable source) - { - return source.AsJEnumerable(); - } + public static IJEnumerable AsJEnumerable(this IEnumerable source) => source.AsJEnumerable(); /// /// Returns the input typed as . diff --git a/Src/Newtonsoft.Json/Linq/JArray.Async.cs b/Src/Newtonsoft.Json/Linq/JArray.Async.cs index 25ffe4efec..af6e1ad378 100644 --- a/Src/Newtonsoft.Json/Linq/JArray.Async.cs +++ b/Src/Newtonsoft.Json/Linq/JArray.Async.cs @@ -60,10 +60,8 @@ public override async Task WriteToAsync(JsonWriter writer, CancellationToken can /// 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) - { - return LoadAsync(reader, null, cancellationToken); - } + public static new Task LoadAsync(JsonReader reader, CancellationToken cancellationToken = default) + => LoadAsync(reader, null, cancellationToken); /// /// Asynchronously loads a from a . diff --git a/Src/Newtonsoft.Json/Linq/JArray.cs b/Src/Newtonsoft.Json/Linq/JArray.cs index c589e211b2..ff9b7df725 100644 --- a/Src/Newtonsoft.Json/Linq/JArray.cs +++ b/Src/Newtonsoft.Json/Linq/JArray.cs @@ -88,30 +88,18 @@ public JArray(params object[] content) /// Initializes a new instance of the class with the specified content. /// /// The contents of the array. - public JArray(object content) - { - Add(content); - } + public JArray(object content) => Add(content); - internal override bool DeepEquals(JToken node) - { - return (node is JArray t && ContentsEqual(t)); - } + internal override bool DeepEquals(JToken node) => (node is JArray t && ContentsEqual(t)); - internal override JToken CloneToken(JsonCloneSettings? settings = null) - { - return new JArray(this, settings); - } + internal override JToken CloneToken(JsonCloneSettings? settings = null) => new JArray(this, settings); /// /// Loads an from a . /// /// A that will be read for the content of the . /// A that contains the JSON that was read from the specified . - public new static JArray Load(JsonReader reader) - { - return Load(reader, null); - } + public new static JArray Load(JsonReader reader) => Load(reader, null); /// /// Loads an from a . @@ -153,10 +141,7 @@ internal override JToken CloneToken(JsonCloneSettings? settings = null) /// /// /// - public new static JArray Parse(string json) - { - return Parse(json, null); - } + public new static JArray Parse(string json) => Parse(json, null); /// /// Load a from a string that contains JSON. @@ -188,10 +173,7 @@ internal override JToken CloneToken(JsonCloneSettings? settings = null) /// /// The object that will be used to create . /// A with the values of the specified object. - public new static JArray FromObject(object o) - { - return FromObject(o, JsonSerializer.CreateDefault()); - } + public new static JArray FromObject(object o) => FromObject(o, JsonSerializer.CreateDefault()); /// /// Creates a from an object. @@ -400,9 +382,6 @@ public bool Remove(JToken item) } #endregion - internal override int GetDeepHashCode() - { - return ContentsHashCode(); - } + internal override int GetDeepHashCode() => ContentsHashCode(); } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Linq/JConstructor.Async.cs b/Src/Newtonsoft.Json/Linq/JConstructor.Async.cs index bdbeff69a0..c727d6dcf5 100644 --- a/Src/Newtonsoft.Json/Linq/JConstructor.Async.cs +++ b/Src/Newtonsoft.Json/Linq/JConstructor.Async.cs @@ -61,10 +61,8 @@ public override async Task WriteToAsync(JsonWriter writer, CancellationToken can /// /// 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) - { - return LoadAsync(reader, null, cancellationToken); - } + public new static Task LoadAsync(JsonReader reader, CancellationToken cancellationToken = default) + => LoadAsync(reader, null, cancellationToken); /// /// Asynchronously loads a from a . diff --git a/Src/Newtonsoft.Json/Linq/JConstructor.cs b/Src/Newtonsoft.Json/Linq/JConstructor.cs index 703dbbc125..7d4a15075e 100644 --- a/Src/Newtonsoft.Json/Linq/JConstructor.cs +++ b/Src/Newtonsoft.Json/Linq/JConstructor.cs @@ -97,16 +97,10 @@ public JConstructor() /// /// A object to copy from. public JConstructor(JConstructor other) - : base(other, settings: null) - { - _name = other.Name; - } + : base(other, settings: null) => _name = other.Name; internal JConstructor(JConstructor other, JsonCloneSettings? settings) - : base(other, settings) - { - _name = other.Name; - } + : base(other, settings) => _name = other.Name; /// /// Initializes a new instance of the class with the specified name and content. @@ -124,10 +118,7 @@ public JConstructor(string name, params object[] content) /// The constructor name. /// The contents of the constructor. public JConstructor(string name, object content) - : this(name) - { - Add(content); - } + : this(name) => Add(content); /// /// Initializes a new instance of the class with the specified name. @@ -148,15 +139,9 @@ public JConstructor(string name) _name = name; } - internal override bool DeepEquals(JToken node) - { - return (node is JConstructor c && _name == c.Name && ContentsEqual(c)); - } + internal override bool DeepEquals(JToken node) => (node is JConstructor c && _name == c.Name && ContentsEqual(c)); - internal override JToken CloneToken(JsonCloneSettings? settings = null) - { - return new JConstructor(this, settings); - } + internal override JToken CloneToken(JsonCloneSettings? settings = null) => new JConstructor(this, settings); /// /// Writes this token to a . @@ -222,10 +207,7 @@ internal override int GetDeepHashCode() /// /// A that will be read for the content of the . /// A that contains the JSON that was read from the specified . - public new static JConstructor Load(JsonReader reader) - { - return Load(reader, null); - } + public new static JConstructor Load(JsonReader reader) => Load(reader, null); /// /// Loads a from a . diff --git a/Src/Newtonsoft.Json/Linq/JContainer.cs b/Src/Newtonsoft.Json/Linq/JContainer.cs index e19be36190..f8bca8275d 100644 --- a/Src/Newtonsoft.Json/Linq/JContainer.cs +++ b/Src/Newtonsoft.Json/Linq/JContainer.cs @@ -136,20 +136,14 @@ internal void CheckReentrancy() #endif } - internal virtual IList CreateChildrenCollection() - { - return new List(); - } + internal virtual IList CreateChildrenCollection() => new List(); #if HAVE_COMPONENT_MODEL /// /// Raises the event. /// /// The instance containing the event data. - protected virtual void OnAddingNew(AddingNewEventArgs e) - { - _addingNew?.Invoke(this, e); - } + protected virtual void OnAddingNew(AddingNewEventArgs e) => _addingNew?.Invoke(this, e); /// /// Raises the event. @@ -268,10 +262,7 @@ public override JToken? Last /// /// An of containing the child tokens of this , in document order. /// - public override JEnumerable Children() - { - return new JEnumerable(ChildrenTokens); - } + public override JEnumerable Children() => new JEnumerable(ChildrenTokens); /// /// Returns a collection of the child values of this token, in document order. @@ -280,28 +271,19 @@ public override JEnumerable Children() /// /// A containing the child values of this , in document order. /// - public override IEnumerable Values() where T : default - { - return ChildrenTokens.Convert(); - } + public override IEnumerable Values() where T : default => ChildrenTokens.Convert(); /// /// Returns a collection of the descendant tokens for this token in document order. /// /// An of containing the descendant tokens of the . - public IEnumerable Descendants() - { - return GetDescendants(false); - } + public IEnumerable Descendants() => GetDescendants(false); /// /// Returns a collection of the tokens that contain this token, and all descendant tokens of this token, in document order. /// /// An of containing this token, and all the descendant tokens of the . - public IEnumerable DescendantsAndSelf() - { - return GetDescendants(true); - } + public IEnumerable DescendantsAndSelf() => GetDescendants(true); internal IEnumerable GetDescendants(bool self) { @@ -323,10 +305,8 @@ internal IEnumerable GetDescendants(bool self) } } - internal bool IsMultiContent([NotNullWhen(true)]object? content) - { - return (content is IEnumerable && !(content is string) && !(content is JToken) && !(content is byte[])); - } + internal bool IsMultiContent([NotNullWhen(true)] object? content) + => (content is IEnumerable && !(content is string) && !(content is JToken) && !(content is byte[])); internal JToken EnsureParentToken(JToken? item, bool skipParentCheck, bool copyAnnotations) { @@ -473,10 +453,7 @@ internal virtual bool RemoveItem(JToken? item) return false; } - internal virtual JToken GetItem(int index) - { - return ChildrenTokens[index]; - } + internal virtual JToken GetItem(int index) => ChildrenTokens[index]; internal virtual void SetItem(int index, JToken? item) { @@ -581,10 +558,7 @@ internal virtual void ReplaceItem(JToken existing, JToken replacement) SetItem(index, replacement); } - internal virtual bool ContainsItem(JToken? item) - { - return (IndexOfItem(item) != -1); - } + internal virtual bool ContainsItem(JToken? item) => (IndexOfItem(item) != -1); internal virtual void CopyItemsTo(Array array, int arrayIndex) { @@ -643,15 +617,9 @@ internal virtual void ValidateToken(JToken o, JToken? existing) /// Adds the specified content as children of this . /// /// The content to be added. - public virtual void Add(object? content) - { - TryAddInternal(ChildrenTokens.Count, content, false, copyAnnotations: true); - } + public virtual void Add(object? content) => TryAddInternal(ChildrenTokens.Count, content, false, copyAnnotations: true); - internal bool TryAdd(object? content) - { - return TryAddInternal(ChildrenTokens.Count, content, false, copyAnnotations: true); - } + internal bool TryAdd(object? content) => TryAddInternal(ChildrenTokens.Count, content, false, copyAnnotations: true); internal void AddAndSkipParentCheck(JToken token) { @@ -662,10 +630,7 @@ internal void AddAndSkipParentCheck(JToken token) /// Adds the specified content as the first children of this . /// /// The content to be added. - public void AddFirst(object? content) - { - TryAddInternal(0, content, false, copyAnnotations: true); - } + public void AddFirst(object? content) => TryAddInternal(0, content, false, copyAnnotations: true); internal bool TryAddInternal(int index, object? content, bool skipParentCheck, bool copyAnnotations) { @@ -704,10 +669,7 @@ internal static JToken CreateFromContent(object? content) /// Creates a that can be used to add tokens to the . /// /// A that is ready to have content written to it. - public JsonWriter CreateWriter() - { - return new JTokenWriter(this); - } + public JsonWriter CreateWriter() => new JTokenWriter(this); /// /// Replaces the child nodes of this token with the specified content. @@ -722,10 +684,7 @@ public void ReplaceAll(object content) /// /// Removes the child nodes from this token. /// - public void RemoveAll() - { - ClearItems(); - } + public void RemoveAll() => ClearItems(); internal abstract void MergeItem(object content, JsonMergeSettings? settings); diff --git a/Src/Newtonsoft.Json/Linq/JEnumerable.cs b/Src/Newtonsoft.Json/Linq/JEnumerable.cs index 41de4c3339..2367b5a733 100644 --- a/Src/Newtonsoft.Json/Linq/JEnumerable.cs +++ b/Src/Newtonsoft.Json/Linq/JEnumerable.cs @@ -65,15 +65,9 @@ public JEnumerable(IEnumerable enumerable) /// /// A that can be used to iterate through the collection. /// - public IEnumerator GetEnumerator() - { - return (_enumerable ?? Empty).GetEnumerator(); - } + public IEnumerator GetEnumerator() => (_enumerable ?? Empty).GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); /// /// Gets the of with the specified key. @@ -99,10 +93,7 @@ public IJEnumerable this[object key] /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(JEnumerable other) - { - return Equals(_enumerable, other._enumerable); - } + public bool Equals(JEnumerable other) => Equals(_enumerable, other._enumerable); /// /// Determines whether the specified is equal to this instance. diff --git a/Src/Newtonsoft.Json/Linq/JObject.Async.cs b/Src/Newtonsoft.Json/Linq/JObject.Async.cs index 67f01fe5f9..ab0c7ae3ee 100644 --- a/Src/Newtonsoft.Json/Linq/JObject.Async.cs +++ b/Src/Newtonsoft.Json/Linq/JObject.Async.cs @@ -82,10 +82,8 @@ async Task AwaitProperties(Task task, int i, JsonWriter Writer, CancellationToke /// /// 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) - { - return LoadAsync(reader, null, cancellationToken); - } + public new static Task LoadAsync(JsonReader reader, CancellationToken cancellationToken = default) + => LoadAsync(reader, null, cancellationToken); /// /// Asynchronously loads a from a . diff --git a/Src/Newtonsoft.Json/Linq/JObject.cs b/Src/Newtonsoft.Json/Linq/JObject.cs index fab460da42..6d95306934 100644 --- a/Src/Newtonsoft.Json/Linq/JObject.cs +++ b/Src/Newtonsoft.Json/Linq/JObject.cs @@ -115,10 +115,7 @@ public JObject(params object[] content) /// Initializes a new instance of the class with the specified content. /// /// The contents of the object. - public JObject(object content) - { - Add(content); - } + public JObject(object content) => Add(content); internal override bool DeepEquals(JToken node) { @@ -242,17 +239,13 @@ internal void InternalPropertyChanged(JProperty childProperty) #endif } - internal void InternalPropertyChanging(JProperty childProperty) - { + internal void InternalPropertyChanging(JProperty childProperty) => #if HAVE_INOTIFY_PROPERTY_CHANGING OnPropertyChanging(childProperty.Name); #endif - } - internal override JToken CloneToken(JsonCloneSettings? settings) - { - return new JObject(this, settings); - } + + internal override JToken CloneToken(JsonCloneSettings? settings) => new JObject(this, settings); /// /// Gets the node type for this . @@ -264,20 +257,14 @@ internal override JToken CloneToken(JsonCloneSettings? settings) /// Gets an of of this object's properties. /// /// An of of this object's properties. - public IEnumerable Properties() - { - return _properties.Cast(); - } + public IEnumerable Properties() => _properties.Cast(); /// /// Gets a with the specified name. /// /// The property name. /// A with the specified name or null. - public JProperty? Property(string name) - { - return Property(name, StringComparison.Ordinal); - } + public JProperty? Property(string name) => Property(name, StringComparison.Ordinal); /// /// Gets the with the specified name. @@ -319,10 +306,7 @@ public IEnumerable Properties() /// Gets a of of this object's property values. /// /// A of of this object's property values. - public JEnumerable PropertyValues() - { - return new JEnumerable(Properties().Select(p => p.Value)); - } + public JEnumerable PropertyValues() => new JEnumerable(Properties().Select(p => p.Value)); /// /// Gets the with the specified key. @@ -394,10 +378,7 @@ public JToken? this[string propertyName] /// /// is not valid JSON. /// - public new static JObject Load(JsonReader reader) - { - return Load(reader, null); - } + public new static JObject Load(JsonReader reader) => Load(reader, null); /// /// Loads a from a . @@ -447,10 +428,7 @@ public JToken? this[string propertyName] /// /// /// - public new static JObject Parse(string json) - { - return Parse(json, null); - } + public new static JObject Parse(string json) => Parse(json, null); /// /// Load a from a string that contains JSON. @@ -485,10 +463,7 @@ public JToken? this[string propertyName] /// /// The object that will be used to create . /// A with the values of the specified object. - public new static JObject FromObject(object o) - { - return FromObject(o, JsonSerializer.CreateDefault()); - } + public new static JObject FromObject(object o) => FromObject(o, JsonSerializer.CreateDefault()); /// /// Creates a from an object. @@ -530,10 +505,7 @@ public override void WriteTo(JsonWriter writer, params JsonConverter[] converter /// /// Name of the property. /// The with the specified property name. - public JToken? GetValue(string? propertyName) - { - return GetValue(propertyName, StringComparison.Ordinal); - } + public JToken? GetValue(string? propertyName) => GetValue(propertyName, StringComparison.Ordinal); /// /// Gets the with the specified property name. @@ -699,10 +671,7 @@ public bool TryGetValue(string propertyName, [NotNullWhen(true)]out JToken? valu } #endregion - internal override int GetDeepHashCode() - { - return ContentsHashCode(); - } + internal override int GetDeepHashCode() => ContentsHashCode(); /// /// Returns an enumerator that can be used to iterate through the collection. @@ -733,9 +702,7 @@ protected virtual void OnPropertyChanged(string propertyName) /// /// Name of the property. protected virtual void OnPropertyChanging(string propertyName) - { - PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(propertyName)); - } + => PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(propertyName)); #endif #if HAVE_COMPONENT_MODEL @@ -827,9 +794,7 @@ EventDescriptorCollection ICustomTypeDescriptor.GetEvents() /// The to bind this object. /// protected override DynamicMetaObject GetMetaObject(Expression parameter) - { - return new DynamicProxyMetaObject(parameter, this, new JObjectDynamicProxy()); - } + => new DynamicProxyMetaObject(parameter, this, new JObjectDynamicProxy()); private class JObjectDynamicProxy : DynamicProxy { @@ -852,10 +817,8 @@ public override bool TrySetMember(JObject instance, SetMemberBinder binder, obje return true; } - public override IEnumerable GetDynamicMemberNames(JObject instance) - { - return instance.Properties().Select(p => p.Name); - } + public override IEnumerable GetDynamicMemberNames(JObject instance) + => instance.Properties().Select(p => p.Name); } #endif } diff --git a/Src/Newtonsoft.Json/Linq/JProperty.Async.cs b/Src/Newtonsoft.Json/Linq/JProperty.Async.cs index d1e845dce0..de535a24b6 100644 --- a/Src/Newtonsoft.Json/Linq/JProperty.Async.cs +++ b/Src/Newtonsoft.Json/Linq/JProperty.Async.cs @@ -74,10 +74,8 @@ private Task WriteValueAsync(JsonWriter writer, CancellationToken cancellationTo /// 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) - { - return LoadAsync(reader, null, cancellationToken); - } + public new static Task LoadAsync(JsonReader reader, CancellationToken cancellationToken = default) + => LoadAsync(reader, null, cancellationToken); /// /// Asynchronously loads a from a . diff --git a/Src/Newtonsoft.Json/Linq/JProperty.cs b/Src/Newtonsoft.Json/Linq/JProperty.cs index b8c7ace6a5..b274cf2e45 100644 --- a/Src/Newtonsoft.Json/Linq/JProperty.cs +++ b/Src/Newtonsoft.Json/Linq/JProperty.cs @@ -187,16 +187,10 @@ public JToken Value /// /// A object to copy from. public JProperty(JProperty other) - : base(other, settings: null) - { - _name = other.Name; - } + : base(other, settings: null) => _name = other.Name; internal JProperty(JProperty other, JsonCloneSettings? settings) - : base(other, settings) - { - _name = other.Name; - } + : base(other, settings) => _name = other.Name; internal override JToken GetItem(int index) { @@ -227,15 +221,11 @@ internal override void SetItem(int index, JToken? item) ((JObject?)Parent)?.InternalPropertyChanged(this); } - internal override bool RemoveItem(JToken? item) - { - throw new JsonException("Cannot add or remove items from {0}.".FormatWith(CultureInfo.InvariantCulture, typeof(JProperty))); - } + internal override bool RemoveItem(JToken? item) + => throw new JsonException("Cannot add or remove items from {0}.".FormatWith(CultureInfo.InvariantCulture, typeof(JProperty))); - internal override void RemoveItemAt(int index) - { - throw new JsonException("Cannot add or remove items from {0}.".FormatWith(CultureInfo.InvariantCulture, typeof(JProperty))); - } + internal override void RemoveItemAt(int index) + => throw new JsonException("Cannot add or remove items from {0}.".FormatWith(CultureInfo.InvariantCulture, typeof(JProperty))); internal override int IndexOfItem(JToken? item) { @@ -263,10 +253,7 @@ internal override bool InsertItem(int index, JToken? item, bool skipParentCheck, return base.InsertItem(0, item, false, copyAnnotations); } - internal override bool ContainsItem(JToken? item) - { - return (Value == item); - } + internal override bool ContainsItem(JToken? item) => (Value == item); internal override void MergeItem(object content, JsonMergeSettings? settings) { @@ -278,20 +265,14 @@ internal override void MergeItem(object content, JsonMergeSettings? settings) } } - internal override void ClearItems() - { - throw new JsonException("Cannot add or remove items from {0}.".FormatWith(CultureInfo.InvariantCulture, typeof(JProperty))); - } + internal override void ClearItems() + => throw new JsonException("Cannot add or remove items from {0}.".FormatWith(CultureInfo.InvariantCulture, typeof(JProperty))); - internal override bool DeepEquals(JToken node) - { - return (node is JProperty t && _name == t.Name && ContentsEqual(t)); - } + internal override bool DeepEquals(JToken node) + => (node is JProperty t && _name == t.Name && ContentsEqual(t)); - internal override JToken CloneToken(JsonCloneSettings? settings) - { - return new JProperty(this, settings); - } + internal override JToken CloneToken(JsonCloneSettings? settings) + => new JProperty(this, settings); /// /// Gets the node type for this . @@ -373,10 +354,7 @@ internal override int GetDeepHashCode() /// /// A that will be read for the content of the . /// A that contains the JSON that was read from the specified . - public new static JProperty Load(JsonReader reader) - { - return Load(reader, null); - } + public new static JProperty Load(JsonReader reader) => Load(reader, null); /// /// Loads a from a . diff --git a/Src/Newtonsoft.Json/Linq/JPropertyDescriptor.cs b/Src/Newtonsoft.Json/Linq/JPropertyDescriptor.cs index 606b2f2dbb..d7f6e92e4a 100644 --- a/Src/Newtonsoft.Json/Linq/JPropertyDescriptor.cs +++ b/Src/Newtonsoft.Json/Linq/JPropertyDescriptor.cs @@ -43,10 +43,7 @@ public JPropertyDescriptor(string name) { } - private static JObject CastInstance(object instance) - { - return (JObject)instance; - } + private static JObject CastInstance(object instance) => (JObject)instance; /// /// When overridden in a derived class, returns whether resetting an object changes its value. @@ -55,10 +52,7 @@ private static JObject CastInstance(object instance) /// true if resetting the component changes its value; otherwise, false. /// /// The component to test for reset capability. - public override bool CanResetValue(object component) - { - return false; - } + public override bool CanResetValue(object component) => false; /// /// When overridden in a derived class, gets the current value of the property on a component. @@ -67,10 +61,7 @@ public override bool CanResetValue(object component) /// The value of a property for a given component. /// /// The component with the property for which to retrieve the value. - public override object? GetValue(object? component) - { - return (component as JObject)?[Name]; - } + public override object? GetValue(object? component) => (component as JObject)?[Name]; /// /// When overridden in a derived class, resets the value for this property of the component to the default value. @@ -102,10 +93,7 @@ public override void SetValue(object? component, object? value) /// true if the property should be persisted; otherwise, false. /// /// The component with the property to be examined for persistence. - public override bool ShouldSerializeValue(object component) - { - return false; - } + public override bool ShouldSerializeValue(object component) => false; /// /// When overridden in a derived class, gets the type of the component this property is bound to. diff --git a/Src/Newtonsoft.Json/Linq/JPropertyKeyedCollection.cs b/Src/Newtonsoft.Json/Linq/JPropertyKeyedCollection.cs index 42a37d8afd..38cb1b78fb 100644 --- a/Src/Newtonsoft.Json/Linq/JPropertyKeyedCollection.cs +++ b/Src/Newtonsoft.Json/Linq/JPropertyKeyedCollection.cs @@ -111,10 +111,7 @@ private void EnsureDictionary() } } - private string GetKeyForItem(JToken item) - { - return ((JProperty)item).Name; - } + private string GetKeyForItem(JToken item) => ((JProperty)item).Name; protected override void InsertItem(int index, JToken item) { @@ -144,10 +141,7 @@ protected override void RemoveItem(int index) base.RemoveItem(index); } - private void RemoveKey(string key) - { - _dictionary?.Remove(key); - } + private void RemoveKey(string key) => _dictionary?.Remove(key); protected override void SetItem(int index, JToken item) { diff --git a/Src/Newtonsoft.Json/Linq/JRaw.cs b/Src/Newtonsoft.Json/Linq/JRaw.cs index 02ca96d3c0..6f574c82b7 100644 --- a/Src/Newtonsoft.Json/Linq/JRaw.cs +++ b/Src/Newtonsoft.Json/Linq/JRaw.cs @@ -72,9 +72,6 @@ public static JRaw Create(JsonReader reader) } } - internal override JToken CloneToken(JsonCloneSettings? settings) - { - return new JRaw(this, settings); - } + internal override JToken CloneToken(JsonCloneSettings? settings) => new JRaw(this, settings); } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Linq/JToken.Async.cs b/Src/Newtonsoft.Json/Linq/JToken.Async.cs index 4d147c2d81..30f493dfdb 100644 --- a/Src/Newtonsoft.Json/Linq/JToken.Async.cs +++ b/Src/Newtonsoft.Json/Linq/JToken.Async.cs @@ -53,10 +53,7 @@ public virtual Task WriteToAsync(JsonWriter writer, CancellationToken cancellati /// A into which this method will write. /// A collection of which will be used when writing the token. /// A that represents the asynchronous write operation. - public Task WriteToAsync(JsonWriter writer, params JsonConverter[] converters) - { - return WriteToAsync(writer, default, converters); - } + public Task WriteToAsync(JsonWriter writer, params JsonConverter[] converters) => WriteToAsync(writer, default, converters); /// /// Asynchronously creates a from a . @@ -70,10 +67,8 @@ public Task WriteToAsync(JsonWriter writer, params JsonConverter[] converters) /// 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) - { - return ReadFromAsync(reader, null, cancellationToken); - } + public static Task ReadFromAsync(JsonReader reader, CancellationToken cancellationToken = default) + => ReadFromAsync(reader, null, cancellationToken); /// /// Asynchronously creates a from a . @@ -150,10 +145,8 @@ public static async Task ReadFromAsync(JsonReader reader, JsonLoadSettin /// 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) - { - return LoadAsync(reader, null, cancellationToken); - } + public static Task LoadAsync(JsonReader reader, CancellationToken cancellationToken = default) + => LoadAsync(reader, null, cancellationToken); /// /// Asynchronously creates a from a . @@ -168,10 +161,8 @@ public static Task LoadAsync(JsonReader reader, CancellationToken cancel /// 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) - { - return ReadFromAsync(reader, settings, cancellationToken); - } + public static Task LoadAsync(JsonReader reader, JsonLoadSettings? settings, CancellationToken cancellationToken = default) + => ReadFromAsync(reader, settings, cancellationToken); } } diff --git a/Src/Newtonsoft.Json/Linq/JToken.cs b/Src/Newtonsoft.Json/Linq/JToken.cs index 27f84d8ba7..cc3b2b6640 100644 --- a/Src/Newtonsoft.Json/Linq/JToken.cs +++ b/Src/Newtonsoft.Json/Linq/JToken.cs @@ -154,10 +154,7 @@ public JToken Root /// The first to compare. /// The second to compare. /// true if the tokens are equal; otherwise false. - public static bool DeepEquals(JToken? t1, JToken? t2) - { - return (t1 == t2 || (t1 != null && t2 != null && t1.DeepEquals(t2))); - } + public static bool DeepEquals(JToken? t1, JToken? t2) => (t1 == t2 || (t1 != null && t2 != null && t1.DeepEquals(t2))); /// /// Gets the next sibling token of this node. diff --git a/Src/Newtonsoft.Json/Linq/JTokenEqualityComparer.cs b/Src/Newtonsoft.Json/Linq/JTokenEqualityComparer.cs index 8e5314b215..225b15f7e7 100644 --- a/Src/Newtonsoft.Json/Linq/JTokenEqualityComparer.cs +++ b/Src/Newtonsoft.Json/Linq/JTokenEqualityComparer.cs @@ -40,10 +40,7 @@ public class JTokenEqualityComparer : IEqualityComparer /// /// true if the specified objects are equal; otherwise, false. /// - public bool Equals(JToken? x, JToken? y) - { - return JToken.DeepEquals(x, y); - } + public bool Equals(JToken? x, JToken? y) => JToken.DeepEquals(x, y); /// /// Returns a hash code for the specified object. diff --git a/Src/Newtonsoft.Json/Linq/JTokenReader.cs b/Src/Newtonsoft.Json/Linq/JTokenReader.cs index 03d21c8a41..8afefb9446 100644 --- a/Src/Newtonsoft.Json/Linq/JTokenReader.cs +++ b/Src/Newtonsoft.Json/Linq/JTokenReader.cs @@ -60,10 +60,7 @@ public JTokenReader(JToken token) /// The token to read from. /// The initial path of the token. It is prepended to the returned . public JTokenReader(JToken token, string initialPath) - : this(token) - { - _initialPath = initialPath; - } + : this(token) => _initialPath = initialPath; /// /// Reads the next JSON token from the underlying . @@ -253,10 +250,7 @@ private void SetToken(JToken token) } } - private string? SafeToString(object? value) - { - return value?.ToString(); - } + private string? SafeToString(object? value) => value?.ToString(); bool IJsonLineInfo.HasLineInfo() { diff --git a/Src/Newtonsoft.Json/Linq/JTokenWriter.cs b/Src/Newtonsoft.Json/Linq/JTokenWriter.cs index 7092e1b7a5..bfa898df83 100644 --- a/Src/Newtonsoft.Json/Linq/JTokenWriter.cs +++ b/Src/Newtonsoft.Json/Linq/JTokenWriter.cs @@ -99,10 +99,7 @@ public override void Flush() /// /// Setting to true has no additional effect, since the underlying is a type that cannot be closed. /// - public override void Close() - { - base.Close(); - } + public override void Close() => base.Close(); /// /// Writes the beginning of a JSON object. @@ -165,10 +162,7 @@ public override void WriteStartConstructor(string name) /// Writes the end. /// /// The token. - protected override void WriteEnd(JsonToken token) - { - RemoveParent(); - } + protected override void WriteEnd(JsonToken token) => RemoveParent(); /// /// Writes the property name of a name/value pair on a JSON object. @@ -187,10 +181,7 @@ public override void WritePropertyName(string name) base.WritePropertyName(name); } - private void AddRawValue(object? value, JTokenType type, JsonToken token) - { - AddJValue(new JValue(value, type), token); - } + private void AddRawValue(object? value, JTokenType type, JsonToken token) => AddJValue(new JValue(value, type), token); internal void AddJValue(JValue? value, JsonToken token) { diff --git a/Src/Newtonsoft.Json/Linq/JsonCloneSettings.cs b/Src/Newtonsoft.Json/Linq/JsonCloneSettings.cs index bad671e43f..f8055a0dab 100644 --- a/Src/Newtonsoft.Json/Linq/JsonCloneSettings.cs +++ b/Src/Newtonsoft.Json/Linq/JsonCloneSettings.cs @@ -32,7 +32,7 @@ namespace Newtonsoft.Json.Linq /// public class JsonCloneSettings { - internal static readonly JsonCloneSettings SkipCopyAnnotations = new JsonCloneSettings + internal static readonly JsonCloneSettings SkipCopyAnnotations = new() { CopyAnnotations = false }; @@ -40,10 +40,7 @@ public class JsonCloneSettings /// /// Initializes a new instance of the class. /// - public JsonCloneSettings() - { - CopyAnnotations = true; - } + public JsonCloneSettings() => CopyAnnotations = true; /// /// Gets or sets a flag that indicates whether to copy annotations when cloning a . diff --git a/Src/Newtonsoft.Json/Linq/JsonMergeSettings.cs b/Src/Newtonsoft.Json/Linq/JsonMergeSettings.cs index 4de8fff608..59207c8d74 100644 --- a/Src/Newtonsoft.Json/Linq/JsonMergeSettings.cs +++ b/Src/Newtonsoft.Json/Linq/JsonMergeSettings.cs @@ -39,10 +39,7 @@ public class JsonMergeSettings /// /// Initializes a new instance of the class. /// - public JsonMergeSettings() - { - _propertyNameComparison = StringComparison.Ordinal; - } + public JsonMergeSettings() => _propertyNameComparison = StringComparison.Ordinal; /// /// Gets or sets the method used when merging JSON arrays. diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/ArrayMultipleIndexFilter.cs b/Src/Newtonsoft.Json/Linq/JsonPath/ArrayMultipleIndexFilter.cs index e1492298b8..fab4e67f72 100644 --- a/Src/Newtonsoft.Json/Linq/JsonPath/ArrayMultipleIndexFilter.cs +++ b/Src/Newtonsoft.Json/Linq/JsonPath/ArrayMultipleIndexFilter.cs @@ -6,10 +6,7 @@ internal class ArrayMultipleIndexFilter : PathFilter { internal List Indexes; - public ArrayMultipleIndexFilter(List indexes) - { - Indexes = indexes; - } + public ArrayMultipleIndexFilter(List indexes) => Indexes = indexes; public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) { diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/FieldFilter.cs b/Src/Newtonsoft.Json/Linq/JsonPath/FieldFilter.cs index 97f638166f..33adf182ea 100644 --- a/Src/Newtonsoft.Json/Linq/JsonPath/FieldFilter.cs +++ b/Src/Newtonsoft.Json/Linq/JsonPath/FieldFilter.cs @@ -8,10 +8,7 @@ internal class FieldFilter : PathFilter { internal string? Name; - public FieldFilter(string? name) - { - Name = name; - } + public FieldFilter(string? name) => Name = name; public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) { diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/FieldMultipleFilter.cs b/Src/Newtonsoft.Json/Linq/JsonPath/FieldMultipleFilter.cs index c3eb7033a4..2e3c6dab2f 100644 --- a/Src/Newtonsoft.Json/Linq/JsonPath/FieldMultipleFilter.cs +++ b/Src/Newtonsoft.Json/Linq/JsonPath/FieldMultipleFilter.cs @@ -13,10 +13,7 @@ internal class FieldMultipleFilter : PathFilter { internal List Names; - public FieldMultipleFilter(List names) - { - Names = names; - } + public FieldMultipleFilter(List names) => Names = names; public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) { diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/QueryExpression.cs b/Src/Newtonsoft.Json/Linq/JsonPath/QueryExpression.cs index 617a7c4191..4c0cdf523a 100644 --- a/Src/Newtonsoft.Json/Linq/JsonPath/QueryExpression.cs +++ b/Src/Newtonsoft.Json/Linq/JsonPath/QueryExpression.cs @@ -34,16 +34,10 @@ internal abstract class QueryExpression { internal QueryOperator Operator; - public QueryExpression(QueryOperator @operator) - { - Operator = @operator; - } + public QueryExpression(QueryOperator @operator) => Operator = @operator; // For unit tests - public bool IsMatch(JToken root, JToken t) - { - return IsMatch(root, t, null); - } + public bool IsMatch(JToken root, JToken t) => IsMatch(root, t, null); public abstract bool IsMatch(JToken root, JToken t, JsonSelectSettings? settings); } @@ -52,10 +46,7 @@ internal class CompositeExpression : QueryExpression { public List Expressions { get; set; } - public CompositeExpression(QueryOperator @operator) : base(@operator) - { - Expressions = new List(); - } + public CompositeExpression(QueryOperator @operator) : base(@operator) => Expressions = new List(); public override bool IsMatch(JToken root, JToken t, JsonSelectSettings? settings) { diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/QueryFilter.cs b/Src/Newtonsoft.Json/Linq/JsonPath/QueryFilter.cs index e844e113f5..a16275e3ae 100644 --- a/Src/Newtonsoft.Json/Linq/JsonPath/QueryFilter.cs +++ b/Src/Newtonsoft.Json/Linq/JsonPath/QueryFilter.cs @@ -7,10 +7,7 @@ internal class QueryFilter : PathFilter { internal QueryExpression Expression; - public QueryFilter(QueryExpression expression) - { - Expression = expression; - } + public QueryFilter(QueryExpression expression) => Expression = expression; public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) { diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/QueryScanFilter.cs b/Src/Newtonsoft.Json/Linq/JsonPath/QueryScanFilter.cs index a1b5270ace..405faf5cf5 100644 --- a/Src/Newtonsoft.Json/Linq/JsonPath/QueryScanFilter.cs +++ b/Src/Newtonsoft.Json/Linq/JsonPath/QueryScanFilter.cs @@ -7,10 +7,7 @@ internal class QueryScanFilter : PathFilter { internal QueryExpression Expression; - public QueryScanFilter(QueryExpression expression) - { - Expression = expression; - } + public QueryScanFilter(QueryExpression expression) => Expression = expression; public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) { diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/RootFilter.cs b/Src/Newtonsoft.Json/Linq/JsonPath/RootFilter.cs index 164ba0c085..8df740591b 100644 --- a/Src/Newtonsoft.Json/Linq/JsonPath/RootFilter.cs +++ b/Src/Newtonsoft.Json/Linq/JsonPath/RootFilter.cs @@ -10,9 +10,7 @@ private RootFilter() { } - public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) - { - return new[] { root }; - } + public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) + => new[] { root }; } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/ScanFilter.cs b/Src/Newtonsoft.Json/Linq/JsonPath/ScanFilter.cs index a3f6adcc34..0595dd1aa2 100644 --- a/Src/Newtonsoft.Json/Linq/JsonPath/ScanFilter.cs +++ b/Src/Newtonsoft.Json/Linq/JsonPath/ScanFilter.cs @@ -6,10 +6,7 @@ internal class ScanFilter : PathFilter { internal string? Name; - public ScanFilter(string? name) - { - Name = name; - } + public ScanFilter(string? name) => Name = name; public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) { diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/ScanMultipleFilter.cs b/Src/Newtonsoft.Json/Linq/JsonPath/ScanMultipleFilter.cs index 40e9334a94..f684f9f593 100644 --- a/Src/Newtonsoft.Json/Linq/JsonPath/ScanMultipleFilter.cs +++ b/Src/Newtonsoft.Json/Linq/JsonPath/ScanMultipleFilter.cs @@ -6,10 +6,7 @@ internal class ScanMultipleFilter : PathFilter { private List _names; - public ScanMultipleFilter(List names) - { - _names = names; - } + public ScanMultipleFilter(List names) => _names = names; public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) { diff --git a/Src/Newtonsoft.Json/Serialization/CachedAttributeGetter.cs b/Src/Newtonsoft.Json/Serialization/CachedAttributeGetter.cs index 4069759418..a1ff72bb1e 100644 --- a/Src/Newtonsoft.Json/Serialization/CachedAttributeGetter.cs +++ b/Src/Newtonsoft.Json/Serialization/CachedAttributeGetter.cs @@ -33,9 +33,6 @@ internal static class CachedAttributeGetter where T : Attribute { private static readonly ThreadSafeStore TypeAttributeCache = new ThreadSafeStore(JsonTypeReflector.GetAttribute); - public static T? GetAttribute(object type) - { - return TypeAttributeCache.Get(type); - } + public static T? GetAttribute(object type) => TypeAttributeCache.Get(type); } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Serialization/CamelCaseNamingStrategy.cs b/Src/Newtonsoft.Json/Serialization/CamelCaseNamingStrategy.cs index 0280c833f0..3f1e1c27d5 100644 --- a/Src/Newtonsoft.Json/Serialization/CamelCaseNamingStrategy.cs +++ b/Src/Newtonsoft.Json/Serialization/CamelCaseNamingStrategy.cs @@ -62,10 +62,7 @@ public CamelCaseNamingStrategy(bool processDictionaryKeys, bool overrideSpecifie /// A flag indicating whether extension data names should be processed. /// public CamelCaseNamingStrategy(bool processDictionaryKeys, bool overrideSpecifiedNames, bool processExtensionDataNames) - : this(processDictionaryKeys, overrideSpecifiedNames) - { - ProcessExtensionDataNames = processExtensionDataNames; - } + : this(processDictionaryKeys, overrideSpecifiedNames) => ProcessExtensionDataNames = processExtensionDataNames; /// /// Initializes a new instance of the class. @@ -79,9 +76,6 @@ public CamelCaseNamingStrategy() /// /// The property name to resolve. /// The resolved property name. - protected override string ResolvePropertyName(string name) - { - return StringUtils.ToCamelCase(name); - } + protected override string ResolvePropertyName(string name) => StringUtils.ToCamelCase(name); } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Serialization/CamelCasePropertyNamesContractResolver.cs b/Src/Newtonsoft.Json/Serialization/CamelCasePropertyNamesContractResolver.cs index 554e89a570..3b4bd3d2c3 100644 --- a/Src/Newtonsoft.Json/Serialization/CamelCasePropertyNamesContractResolver.cs +++ b/Src/Newtonsoft.Json/Serialization/CamelCasePropertyNamesContractResolver.cs @@ -42,14 +42,12 @@ public class CamelCasePropertyNamesContractResolver : DefaultContractResolver /// /// Initializes a new instance of the class. /// - public CamelCasePropertyNamesContractResolver() - { + public CamelCasePropertyNamesContractResolver() => NamingStrategy = new CamelCaseNamingStrategy { ProcessDictionaryKeys = true, OverrideSpecifiedNames = true }; - } /// /// Resolves the contract for a given type. @@ -86,9 +84,6 @@ public override JsonContract ResolveContract(Type type) return contract; } - internal override DefaultJsonNameTable GetNameTable() - { - return NameTable; - } + internal override DefaultJsonNameTable GetNameTable() => NameTable; } } \ No newline at end of file