From 993215529562866719689206e27e413013d4439c Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Mon, 23 Oct 2017 09:49:12 +1300 Subject: [PATCH] -Refactor to expression body properties --- Src/Newtonsoft.Json/Bson/BsonReader.cs | 12 +- Src/Newtonsoft.Json/Bson/BsonToken.cs | 25 +--- Src/Newtonsoft.Json/Bson/BsonWriter.cs | 4 +- .../Converters/CustomCreationConverter.cs | 5 +- .../Converters/IsoDateTimeConverter.cs | 12 +- Src/Newtonsoft.Json/JsonArrayAttribute.cs | 4 +- Src/Newtonsoft.Json/JsonContainerAttribute.cs | 20 +-- Src/Newtonsoft.Json/JsonConverter.cs | 10 +- Src/Newtonsoft.Json/JsonConverterAttribute.cs | 5 +- Src/Newtonsoft.Json/JsonObjectAttribute.cs | 8 +- Src/Newtonsoft.Json/JsonPropertyAttribute.cs | 44 +++--- Src/Newtonsoft.Json/JsonReader.cs | 47 +++---- Src/Newtonsoft.Json/JsonTextReader.cs | 12 +- Src/Newtonsoft.Json/JsonTextWriter.cs | 12 +- Src/Newtonsoft.Json/JsonValidatingReader.cs | 52 ++------ Src/Newtonsoft.Json/JsonWriter.cs | 18 +-- Src/Newtonsoft.Json/Linq/JArray.cs | 19 +-- Src/Newtonsoft.Json/Linq/JConstructor.cs | 14 +- Src/Newtonsoft.Json/Linq/JContainer.cs | 91 ++++--------- Src/Newtonsoft.Json/Linq/JObject.cs | 31 +---- Src/Newtonsoft.Json/Linq/JProperty.cs | 17 +-- .../Linq/JPropertyDescriptor.cs | 15 +-- Src/Newtonsoft.Json/Linq/JToken.cs | 27 ++-- Src/Newtonsoft.Json/Linq/JTokenReader.cs | 5 +- Src/Newtonsoft.Json/Linq/JTokenWriter.cs | 5 +- Src/Newtonsoft.Json/Linq/JValue.cs | 12 +- Src/Newtonsoft.Json/Linq/JsonLoadSettings.cs | 4 +- Src/Newtonsoft.Json/Linq/JsonMergeSettings.cs | 4 +- Src/Newtonsoft.Json/Schema/JsonSchema.cs | 5 +- .../Schema/JsonSchemaBuilder.cs | 5 +- .../Schema/JsonSchemaGenerator.cs | 7 +- .../Schema/ValidationEventArgs.cs | 15 +-- .../Serialization/DefaultContractResolver.cs | 10 +- .../Serialization/JsonArrayContract.cs | 7 +- .../Serialization/JsonContainerContract.cs | 7 +- .../Serialization/JsonContract.cs | 2 +- .../Serialization/JsonDictionaryContract.cs | 9 +- .../Serialization/JsonObjectContract.cs | 10 +- .../Serialization/JsonPrimitiveContract.cs | 3 +- .../Serialization/JsonProperty.cs | 12 +- .../Serialization/JsonSerializerProxy.cs | 125 +++++++++--------- .../Serialization/TraceJsonReader.cs | 29 +--- .../Utilities/CollectionWrapper.cs | 10 +- .../Utilities/DictionaryWrapper.cs | 20 +-- .../DynamicReflectionDelegateFactory.cs | 5 +- Src/Newtonsoft.Json/Utilities/EnumValue.cs | 10 +- .../LateBoundReflectionDelegateFactory.cs | 5 +- Src/Newtonsoft.Json/Utilities/LinqBridge.cs | 7 +- Src/Newtonsoft.Json/Utilities/StringBuffer.cs | 14 +- .../Utilities/StringReference.cs | 20 +-- 50 files changed, 285 insertions(+), 586 deletions(-) diff --git a/Src/Newtonsoft.Json/Bson/BsonReader.cs b/Src/Newtonsoft.Json/Bson/BsonReader.cs index 96a57664..2775b579 100644 --- a/Src/Newtonsoft.Json/Bson/BsonReader.cs +++ b/Src/Newtonsoft.Json/Bson/BsonReader.cs @@ -94,8 +94,8 @@ namespace Newtonsoft.Json.Bson [Obsolete("JsonNet35BinaryCompatibility will be removed in a future version of Json.NET.")] public bool JsonNet35BinaryCompatibility { - get { return _jsonNet35BinaryCompatibility; } - set { _jsonNet35BinaryCompatibility = value; } + get => _jsonNet35BinaryCompatibility; + set => _jsonNet35BinaryCompatibility = value; } /// @@ -106,8 +106,8 @@ namespace Newtonsoft.Json.Bson /// public bool ReadRootValueAsArray { - get { return _readRootValueAsArray; } - set { _readRootValueAsArray = value; } + get => _readRootValueAsArray; + set => _readRootValueAsArray = value; } /// @@ -116,8 +116,8 @@ namespace Newtonsoft.Json.Bson /// The used when reading values from BSON. public DateTimeKind DateTimeKindHandling { - get { return _dateTimeKindHandling; } - set { _dateTimeKindHandling = value; } + get => _dateTimeKindHandling; + set => _dateTimeKindHandling = value; } /// diff --git a/Src/Newtonsoft.Json/Bson/BsonToken.cs b/Src/Newtonsoft.Json/Bson/BsonToken.cs index d8b808cd..631584c9 100644 --- a/Src/Newtonsoft.Json/Bson/BsonToken.cs +++ b/Src/Newtonsoft.Json/Bson/BsonToken.cs @@ -45,10 +45,7 @@ namespace Newtonsoft.Json.Bson token.Parent = this; } - public override BsonType Type - { - get { return BsonType.Object; } - } + public override BsonType Type => BsonType.Object; public IEnumerator GetEnumerator() { @@ -71,10 +68,7 @@ namespace Newtonsoft.Json.Bson token.Parent = this; } - public override BsonType Type - { - get { return BsonType.Array; } - } + public override BsonType Type => BsonType.Array; public IEnumerator GetEnumerator() { @@ -111,15 +105,9 @@ namespace Newtonsoft.Json.Bson _type = type; } - public object Value - { - get { return _value; } - } + public object Value => _value; - public override BsonType Type - { - get { return _type; } - } + public override BsonType Type => _type; } internal class BsonBoolean : BsonValue @@ -167,10 +155,7 @@ namespace Newtonsoft.Json.Bson Options = new BsonString(options, false); } - public override BsonType Type - { - get { return BsonType.Regex; } - } + public override BsonType Type => BsonType.Regex; } internal class BsonProperty diff --git a/Src/Newtonsoft.Json/Bson/BsonWriter.cs b/Src/Newtonsoft.Json/Bson/BsonWriter.cs index 1540d14a..5d5500a7 100644 --- a/Src/Newtonsoft.Json/Bson/BsonWriter.cs +++ b/Src/Newtonsoft.Json/Bson/BsonWriter.cs @@ -56,8 +56,8 @@ namespace Newtonsoft.Json.Bson /// The used when writing values to BSON. public DateTimeKind DateTimeKindHandling { - get { return _writer.DateTimeKindHandling; } - set { _writer.DateTimeKindHandling = value; } + get => _writer.DateTimeKindHandling; + set => _writer.DateTimeKindHandling = value; } /// diff --git a/Src/Newtonsoft.Json/Converters/CustomCreationConverter.cs b/Src/Newtonsoft.Json/Converters/CustomCreationConverter.cs index dbef8f85..8f54c0c6 100644 --- a/Src/Newtonsoft.Json/Converters/CustomCreationConverter.cs +++ b/Src/Newtonsoft.Json/Converters/CustomCreationConverter.cs @@ -96,9 +96,6 @@ namespace Newtonsoft.Json.Converters /// /// true if this can write JSON; otherwise, false. /// - public override bool CanWrite - { - get { return false; } - } + public override bool CanWrite => false; } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs b/Src/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs index 7f058df8..5a2e9322 100644 --- a/Src/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs +++ b/Src/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs @@ -46,8 +46,8 @@ namespace Newtonsoft.Json.Converters /// The date time styles used when converting a date to and from JSON. public DateTimeStyles DateTimeStyles { - get { return _dateTimeStyles; } - set { _dateTimeStyles = value; } + get => _dateTimeStyles; + set => _dateTimeStyles = value; } /// @@ -56,8 +56,8 @@ namespace Newtonsoft.Json.Converters /// The date time format used when converting a date to and from JSON. public string DateTimeFormat { - get { return _dateTimeFormat ?? string.Empty; } - set { _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value; } + get => _dateTimeFormat ?? string.Empty; + set => _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value; } /// @@ -66,8 +66,8 @@ namespace Newtonsoft.Json.Converters /// The culture used when converting a date to and from JSON. public CultureInfo Culture { - get { return _culture ?? CultureInfo.CurrentCulture; } - set { _culture = value; } + get => _culture ?? CultureInfo.CurrentCulture; + set => _culture = value; } /// diff --git a/Src/Newtonsoft.Json/JsonArrayAttribute.cs b/Src/Newtonsoft.Json/JsonArrayAttribute.cs index ce4a77e6..96221a7a 100644 --- a/Src/Newtonsoft.Json/JsonArrayAttribute.cs +++ b/Src/Newtonsoft.Json/JsonArrayAttribute.cs @@ -41,8 +41,8 @@ namespace Newtonsoft.Json /// true if null items are allowed in the collection; otherwise, false. public bool AllowNullItems { - get { return _allowNullItems; } - set { _allowNullItems = value; } + get => _allowNullItems; + set => _allowNullItems = value; } /// diff --git a/Src/Newtonsoft.Json/JsonContainerAttribute.cs b/Src/Newtonsoft.Json/JsonContainerAttribute.cs index 266d2b47..c04cd4b7 100644 --- a/Src/Newtonsoft.Json/JsonContainerAttribute.cs +++ b/Src/Newtonsoft.Json/JsonContainerAttribute.cs @@ -77,7 +77,7 @@ namespace Newtonsoft.Json /// The of the . public Type NamingStrategyType { - get { return _namingStrategyType; } + get => _namingStrategyType; set { _namingStrategyType = value; @@ -98,7 +98,7 @@ namespace Newtonsoft.Json /// public object[] NamingStrategyParameters { - get { return _namingStrategyParameters; } + get => _namingStrategyParameters; set { _namingStrategyParameters = value; @@ -125,8 +125,8 @@ namespace Newtonsoft.Json /// public bool IsReference { - get { return _isReference ?? default(bool); } - set { _isReference = value; } + get => _isReference ?? default(bool); + set => _isReference = value; } /// @@ -137,8 +137,8 @@ namespace Newtonsoft.Json /// public bool ItemIsReference { - get { return _itemIsReference ?? default(bool); } - set { _itemIsReference = value; } + get => _itemIsReference ?? default(bool); + set => _itemIsReference = value; } /// @@ -147,8 +147,8 @@ namespace Newtonsoft.Json /// The reference loop handling. public ReferenceLoopHandling ItemReferenceLoopHandling { - get { return _itemReferenceLoopHandling ?? default(ReferenceLoopHandling); } - set { _itemReferenceLoopHandling = value; } + get => _itemReferenceLoopHandling ?? default(ReferenceLoopHandling); + set => _itemReferenceLoopHandling = value; } /// @@ -157,8 +157,8 @@ namespace Newtonsoft.Json /// The type name handling. public TypeNameHandling ItemTypeNameHandling { - get { return _itemTypeNameHandling ?? default(TypeNameHandling); } - set { _itemTypeNameHandling = value; } + get => _itemTypeNameHandling ?? default(TypeNameHandling); + set => _itemTypeNameHandling = value; } /// diff --git a/Src/Newtonsoft.Json/JsonConverter.cs b/Src/Newtonsoft.Json/JsonConverter.cs index 3735844f..fc9bc256 100644 --- a/Src/Newtonsoft.Json/JsonConverter.cs +++ b/Src/Newtonsoft.Json/JsonConverter.cs @@ -65,19 +65,13 @@ namespace Newtonsoft.Json /// Gets a value indicating whether this can read JSON. /// /// true if this can read JSON; otherwise, false. - public virtual bool CanRead - { - get { return true; } - } + public virtual bool CanRead => true; /// /// Gets a value indicating whether this can write JSON. /// /// true if this can write JSON; otherwise, false. - public virtual bool CanWrite - { - get { return true; } - } + public virtual bool CanWrite => true; } /// diff --git a/Src/Newtonsoft.Json/JsonConverterAttribute.cs b/Src/Newtonsoft.Json/JsonConverterAttribute.cs index 4ccceeb9..2c09128c 100644 --- a/Src/Newtonsoft.Json/JsonConverterAttribute.cs +++ b/Src/Newtonsoft.Json/JsonConverterAttribute.cs @@ -41,10 +41,7 @@ namespace Newtonsoft.Json /// Gets the of the . /// /// The of the . - public Type ConverterType - { - get { return _converterType; } - } + public Type ConverterType => _converterType; /// /// The parameter list to use when constructing the described by . diff --git a/Src/Newtonsoft.Json/JsonObjectAttribute.cs b/Src/Newtonsoft.Json/JsonObjectAttribute.cs index 61fad921..5f824993 100644 --- a/Src/Newtonsoft.Json/JsonObjectAttribute.cs +++ b/Src/Newtonsoft.Json/JsonObjectAttribute.cs @@ -45,8 +45,8 @@ namespace Newtonsoft.Json /// The member serialization. public MemberSerialization MemberSerialization { - get { return _memberSerialization; } - set { _memberSerialization = value; } + get => _memberSerialization; + set => _memberSerialization = value; } /// @@ -57,8 +57,8 @@ namespace Newtonsoft.Json /// public Required ItemRequired { - get { return _itemRequired ?? default(Required); } - set { _itemRequired = value; } + get => _itemRequired ?? default(Required); + set => _itemRequired = value; } /// diff --git a/Src/Newtonsoft.Json/JsonPropertyAttribute.cs b/Src/Newtonsoft.Json/JsonPropertyAttribute.cs index 4e7518d6..56bbd865 100644 --- a/Src/Newtonsoft.Json/JsonPropertyAttribute.cs +++ b/Src/Newtonsoft.Json/JsonPropertyAttribute.cs @@ -92,8 +92,8 @@ namespace Newtonsoft.Json /// The null value handling. public NullValueHandling NullValueHandling { - get { return _nullValueHandling ?? default(NullValueHandling); } - set { _nullValueHandling = value; } + get => _nullValueHandling ?? default(NullValueHandling); + set => _nullValueHandling = value; } /// @@ -102,8 +102,8 @@ namespace Newtonsoft.Json /// The default value handling. public DefaultValueHandling DefaultValueHandling { - get { return _defaultValueHandling ?? default(DefaultValueHandling); } - set { _defaultValueHandling = value; } + get => _defaultValueHandling ?? default(DefaultValueHandling); + set => _defaultValueHandling = value; } /// @@ -112,8 +112,8 @@ namespace Newtonsoft.Json /// The reference loop handling. public ReferenceLoopHandling ReferenceLoopHandling { - get { return _referenceLoopHandling ?? default(ReferenceLoopHandling); } - set { _referenceLoopHandling = value; } + get => _referenceLoopHandling ?? default(ReferenceLoopHandling); + set => _referenceLoopHandling = value; } /// @@ -122,8 +122,8 @@ namespace Newtonsoft.Json /// The object creation handling. public ObjectCreationHandling ObjectCreationHandling { - get { return _objectCreationHandling ?? default(ObjectCreationHandling); } - set { _objectCreationHandling = value; } + get => _objectCreationHandling ?? default(ObjectCreationHandling); + set => _objectCreationHandling = value; } /// @@ -132,8 +132,8 @@ namespace Newtonsoft.Json /// The type name handling. public TypeNameHandling TypeNameHandling { - get { return _typeNameHandling ?? default(TypeNameHandling); } - set { _typeNameHandling = value; } + get => _typeNameHandling ?? default(TypeNameHandling); + set => _typeNameHandling = value; } /// @@ -142,8 +142,8 @@ namespace Newtonsoft.Json /// Whether this property's value is serialized as a reference. public bool IsReference { - get { return _isReference ?? default(bool); } - set { _isReference = value; } + get => _isReference ?? default(bool); + set => _isReference = value; } /// @@ -152,8 +152,8 @@ namespace Newtonsoft.Json /// The numeric order of serialization. public int Order { - get { return _order ?? default(int); } - set { _order = value; } + get => _order ?? default(int); + set => _order = value; } /// @@ -164,8 +164,8 @@ namespace Newtonsoft.Json /// public Required Required { - get { return _required ?? Required.Default; } - set { _required = value; } + get => _required ?? Required.Default; + set => _required = value; } /// @@ -180,8 +180,8 @@ namespace Newtonsoft.Json /// The collection's items reference loop handling. public ReferenceLoopHandling ItemReferenceLoopHandling { - get { return _itemReferenceLoopHandling ?? default(ReferenceLoopHandling); } - set { _itemReferenceLoopHandling = value; } + get => _itemReferenceLoopHandling ?? default(ReferenceLoopHandling); + set => _itemReferenceLoopHandling = value; } /// @@ -190,8 +190,8 @@ namespace Newtonsoft.Json /// The collection's items type name handling. public TypeNameHandling ItemTypeNameHandling { - get { return _itemTypeNameHandling ?? default(TypeNameHandling); } - set { _itemTypeNameHandling = value; } + get => _itemTypeNameHandling ?? default(TypeNameHandling); + set => _itemTypeNameHandling = value; } /// @@ -200,8 +200,8 @@ namespace Newtonsoft.Json /// Whether this property's collection items are serialized as a reference. public bool ItemIsReference { - get { return _itemIsReference ?? default(bool); } - set { _itemIsReference = value; } + get => _itemIsReference ?? default(bool); + set => _itemIsReference = value; } /// diff --git a/Src/Newtonsoft.Json/JsonReader.cs b/Src/Newtonsoft.Json/JsonReader.cs index 58ad7471..17222f99 100644 --- a/Src/Newtonsoft.Json/JsonReader.cs +++ b/Src/Newtonsoft.Json/JsonReader.cs @@ -32,11 +32,6 @@ using System.Numerics; #endif using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Utilities; -#if !HAVE_LINQ -using Newtonsoft.Json.Utilities.LinqBridge; -#else -using System.Linq; -#endif namespace Newtonsoft.Json { @@ -135,10 +130,7 @@ namespace Newtonsoft.Json /// Gets the current reader state. /// /// The current reader state. - protected State CurrentState - { - get { return _currentState; } - } + protected State CurrentState => _currentState; /// /// Gets or sets a value indicating whether the source should be closed when this reader is closed. @@ -163,8 +155,8 @@ namespace Newtonsoft.Json /// public virtual char QuoteChar { - get { return _quoteChar; } - protected internal set { _quoteChar = value; } + get => _quoteChar; + protected internal set => _quoteChar = value; } /// @@ -172,7 +164,7 @@ namespace Newtonsoft.Json /// public DateTimeZoneHandling DateTimeZoneHandling { - get { return _dateTimeZoneHandling; } + get => _dateTimeZoneHandling; set { if (value < DateTimeZoneHandling.Local || value > DateTimeZoneHandling.RoundtripKind) @@ -189,7 +181,7 @@ namespace Newtonsoft.Json /// public DateParseHandling DateParseHandling { - get { return _dateParseHandling; } + get => _dateParseHandling; set { if (value < DateParseHandling.None || @@ -212,7 +204,7 @@ namespace Newtonsoft.Json /// public FloatParseHandling FloatParseHandling { - get { return _floatParseHandling; } + get => _floatParseHandling; set { if (value < FloatParseHandling.Double || value > FloatParseHandling.Decimal) @@ -229,8 +221,8 @@ namespace Newtonsoft.Json /// public string DateFormatString { - get { return _dateFormatString; } - set { _dateFormatString = value; } + get => _dateFormatString; + set => _dateFormatString = value; } /// @@ -238,7 +230,7 @@ namespace Newtonsoft.Json /// public int? MaxDepth { - get { return _maxDepth; } + get => _maxDepth; set { if (value <= 0) @@ -253,26 +245,17 @@ namespace Newtonsoft.Json /// /// Gets the type of the current JSON token. /// - public virtual JsonToken TokenType - { - get { return _tokenType; } - } + public virtual JsonToken TokenType => _tokenType; /// /// Gets the text value of the current JSON token. /// - public virtual object Value - { - get { return _value; } - } + public virtual object Value => _value; /// /// Gets the .NET type for the current JSON token. /// - public virtual Type ValueType - { - get { return _value?.GetType(); } - } + public virtual Type ValueType => _value?.GetType(); /// /// Gets the depth of the current token in the JSON document. @@ -282,7 +265,7 @@ namespace Newtonsoft.Json { get { - int depth = (_stack != null) ? _stack.Count : 0; + int depth = _stack?.Count ?? 0; if (JsonTokenUtils.IsStartToken(TokenType) || _currentPosition.Type == JsonContainerType.None) { return depth; @@ -321,8 +304,8 @@ namespace Newtonsoft.Json /// public CultureInfo Culture { - get { return _culture ?? CultureInfo.InvariantCulture; } - set { _culture = value; } + get => _culture ?? CultureInfo.InvariantCulture; + set => _culture = value; } internal JsonPosition GetPosition(int depth) diff --git a/Src/Newtonsoft.Json/JsonTextReader.cs b/Src/Newtonsoft.Json/JsonTextReader.cs index 47a0e126..78135b77 100644 --- a/Src/Newtonsoft.Json/JsonTextReader.cs +++ b/Src/Newtonsoft.Json/JsonTextReader.cs @@ -102,10 +102,7 @@ namespace Newtonsoft.Json set => _chars = value; } - internal int CharPos - { - get => _charPos; - } + internal int CharPos => _charPos; #endif /// @@ -113,7 +110,7 @@ namespace Newtonsoft.Json /// public IArrayPool ArrayPool { - get { return _arrayPool; } + get => _arrayPool; set { if (value == null) @@ -2582,9 +2579,6 @@ namespace Newtonsoft.Json /// /// The current line position or 0 if no line information is available (for example, returns false). /// - public int LinePosition - { - get { return _charPos - _lineStartPos; } - } + public int LinePosition => _charPos - _lineStartPos; } } diff --git a/Src/Newtonsoft.Json/JsonTextWriter.cs b/Src/Newtonsoft.Json/JsonTextWriter.cs index 743d760e..d70cafcd 100644 --- a/Src/Newtonsoft.Json/JsonTextWriter.cs +++ b/Src/Newtonsoft.Json/JsonTextWriter.cs @@ -71,7 +71,7 @@ namespace Newtonsoft.Json /// public IArrayPool ArrayPool { - get { return _arrayPool; } + get => _arrayPool; set { if (value == null) @@ -88,7 +88,7 @@ namespace Newtonsoft.Json /// public int Indentation { - get { return _indentation; } + get => _indentation; set { if (value < 0) @@ -105,7 +105,7 @@ namespace Newtonsoft.Json /// public char QuoteChar { - get { return _quoteChar; } + get => _quoteChar; set { if (value != '"' && value != '\'') @@ -123,7 +123,7 @@ namespace Newtonsoft.Json /// public char IndentChar { - get { return _indentChar; } + get => _indentChar; set { if (value != _indentChar) @@ -139,8 +139,8 @@ namespace Newtonsoft.Json /// public bool QuoteName { - get { return _quoteName; } - set { _quoteName = value; } + get => _quoteName; + set => _quoteName = value; } /// diff --git a/Src/Newtonsoft.Json/JsonValidatingReader.cs b/Src/Newtonsoft.Json/JsonValidatingReader.cs index 677a49c6..05a5aab3 100644 --- a/Src/Newtonsoft.Json/JsonValidatingReader.cs +++ b/Src/Newtonsoft.Json/JsonValidatingReader.cs @@ -66,20 +66,11 @@ namespace Newtonsoft.Json public IList UniqueArrayItems { get; } public JTokenWriter CurrentItemWriter { get; set; } - public IList Schemas - { - get { return _schemas; } - } + public IList Schemas => _schemas; - public Dictionary RequiredProperties - { - get { return _requiredProperties; } - } + public Dictionary RequiredProperties => _requiredProperties; - public JTokenType TokenType - { - get { return _tokenType; } - } + public JTokenType TokenType => _tokenType; public SchemaScope(JTokenType tokenType, IList schemas) { @@ -121,27 +112,18 @@ namespace Newtonsoft.Json /// Gets the text value of the current JSON token. /// /// - public override object Value - { - get { return _reader.Value; } - } + public override object Value => _reader.Value; /// /// Gets the depth of the current token in the JSON document. /// /// The depth of the current token in the JSON document. - public override int Depth - { - get { return _reader.Depth; } - } + public override int Depth => _reader.Depth; /// /// Gets the path of the current JSON token. /// - public override string Path - { - get { return _reader.Path; } - } + public override string Path => _reader.Path; /// /// Gets the quotation mark character used to enclose the value of a string. @@ -157,19 +139,13 @@ namespace Newtonsoft.Json /// Gets the type of the current JSON token. /// /// - public override JsonToken TokenType - { - get { return _reader.TokenType; } - } + public override JsonToken TokenType => _reader.TokenType; /// /// Gets the .NET type for the current JSON token. /// /// - public override Type ValueType - { - get { return _reader.ValueType; } - } + public override Type ValueType => _reader.ValueType; private void Push(SchemaScope scope) { @@ -187,10 +163,7 @@ namespace Newtonsoft.Json return poppedScope; } - private IList CurrentSchemas - { - get { return _currentScope.Schemas; } - } + private IList CurrentSchemas => _currentScope.Schemas; private static readonly IList EmptySchemaList = new List(); @@ -329,7 +302,7 @@ namespace Newtonsoft.Json /// The schema. public JsonSchema Schema { - get { return _schema; } + get => _schema; set { if (TokenType != JsonToken.None) @@ -346,10 +319,7 @@ namespace Newtonsoft.Json /// Gets the used to construct this . /// /// The specified in the constructor. - public JsonReader Reader - { - get { return _reader; } - } + public JsonReader Reader => _reader; /// /// Changes the reader's state to . diff --git a/Src/Newtonsoft.Json/JsonWriter.cs b/Src/Newtonsoft.Json/JsonWriter.cs index 91346c0e..f3df862d 100644 --- a/Src/Newtonsoft.Json/JsonWriter.cs +++ b/Src/Newtonsoft.Json/JsonWriter.cs @@ -231,7 +231,7 @@ namespace Newtonsoft.Json /// public Formatting Formatting { - get { return _formatting; } + get => _formatting; set { if (value < Formatting.None || value > Formatting.Indented) @@ -248,7 +248,7 @@ namespace Newtonsoft.Json /// public DateFormatHandling DateFormatHandling { - get { return _dateFormatHandling; } + get => _dateFormatHandling; set { if (value < DateFormatHandling.IsoDateFormat || value > DateFormatHandling.MicrosoftDateFormat) @@ -265,7 +265,7 @@ namespace Newtonsoft.Json /// public DateTimeZoneHandling DateTimeZoneHandling { - get { return _dateTimeZoneHandling; } + get => _dateTimeZoneHandling; set { if (value < DateTimeZoneHandling.Local || value > DateTimeZoneHandling.RoundtripKind) @@ -282,7 +282,7 @@ namespace Newtonsoft.Json /// public StringEscapeHandling StringEscapeHandling { - get { return _stringEscapeHandling; } + get => _stringEscapeHandling; set { if (value < StringEscapeHandling.Default || value > StringEscapeHandling.EscapeHtml) @@ -307,7 +307,7 @@ namespace Newtonsoft.Json /// public FloatFormatHandling FloatFormatHandling { - get { return _floatFormatHandling; } + get => _floatFormatHandling; set { if (value < FloatFormatHandling.String || value > FloatFormatHandling.DefaultValue) @@ -324,8 +324,8 @@ namespace Newtonsoft.Json /// public string DateFormatString { - get { return _dateFormatString; } - set { _dateFormatString = value; } + get => _dateFormatString; + set => _dateFormatString = value; } /// @@ -333,8 +333,8 @@ namespace Newtonsoft.Json /// public CultureInfo Culture { - get { return _culture ?? CultureInfo.InvariantCulture; } - set { _culture = value; } + get => _culture ?? CultureInfo.InvariantCulture; + set => _culture = value; } /// diff --git a/Src/Newtonsoft.Json/Linq/JArray.cs b/Src/Newtonsoft.Json/Linq/JArray.cs index 17b1c150..90f25c8d 100644 --- a/Src/Newtonsoft.Json/Linq/JArray.cs +++ b/Src/Newtonsoft.Json/Linq/JArray.cs @@ -46,19 +46,13 @@ namespace Newtonsoft.Json.Linq /// Gets the container's children tokens. /// /// The container's children tokens. - protected override IList ChildrenTokens - { - get { return _values; } - } + protected override IList ChildrenTokens => _values; /// /// Gets the node type for this . /// /// The type. - public override JTokenType Type - { - get { return JTokenType.Array; } - } + public override JTokenType Type => JTokenType.Array; /// /// Initializes a new instance of the class. @@ -266,8 +260,8 @@ namespace Newtonsoft.Json.Linq /// public JToken this[int index] { - get { return GetItem(index); } - set { SetItem(index, value); } + get => GetItem(index); + set => SetItem(index, value); } internal override int IndexOfItem(JToken item) @@ -382,10 +376,7 @@ namespace Newtonsoft.Json.Linq /// Gets a value indicating whether the is read-only. /// /// true if the is read-only; otherwise, false. - public bool IsReadOnly - { - get { return false; } - } + public bool IsReadOnly => false; /// /// Removes the first occurrence of a specific object from the . diff --git a/Src/Newtonsoft.Json/Linq/JConstructor.cs b/Src/Newtonsoft.Json/Linq/JConstructor.cs index ff7412d8..966bc5b0 100644 --- a/Src/Newtonsoft.Json/Linq/JConstructor.cs +++ b/Src/Newtonsoft.Json/Linq/JConstructor.cs @@ -43,10 +43,7 @@ namespace Newtonsoft.Json.Linq /// Gets the container's children tokens. /// /// The container's children tokens. - protected override IList ChildrenTokens - { - get { return _values; } - } + protected override IList ChildrenTokens => _values; internal override int IndexOfItem(JToken item) { @@ -74,18 +71,15 @@ namespace Newtonsoft.Json.Linq /// The constructor name. public string Name { - get { return _name; } - set { _name = value; } + get => _name; + set => _name = value; } /// /// Gets the node type for this . /// /// The type. - public override JTokenType Type - { - get { return JTokenType.Constructor; } - } + public override JTokenType Type => JTokenType.Constructor; /// /// Initializes a new instance of the class. diff --git a/Src/Newtonsoft.Json/Linq/JContainer.cs b/Src/Newtonsoft.Json/Linq/JContainer.cs index 6eaa279e..0d54b89d 100644 --- a/Src/Newtonsoft.Json/Linq/JContainer.cs +++ b/Src/Newtonsoft.Json/Linq/JContainer.cs @@ -63,8 +63,8 @@ namespace Newtonsoft.Json.Linq /// public event ListChangedEventHandler ListChanged { - add { _listChanged += value; } - remove { _listChanged -= value; } + add => _listChanged += value; + remove => _listChanged -= value; } /// @@ -72,8 +72,8 @@ namespace Newtonsoft.Json.Linq /// public event AddingNewEventHandler AddingNew { - add { _addingNew += value; } - remove { _addingNew -= value; } + add => _addingNew += value; + remove => _addingNew -= value; } #endif #if HAVE_INOTIFY_COLLECTION_CHANGED @@ -194,10 +194,7 @@ namespace Newtonsoft.Json.Linq /// /// true if this token has child values; otherwise, false. /// - public override bool HasValues - { - get { return ChildrenTokens.Count > 0; } - } + public override bool HasValues => ChildrenTokens.Count > 0; internal bool ContentsEqual(JContainer container) { @@ -906,8 +903,8 @@ namespace Newtonsoft.Json.Linq JToken IList.this[int index] { - get { return GetItem(index); } - set { SetItem(index, value); } + get => GetItem(index); + set => SetItem(index, value); } #endregion @@ -932,10 +929,7 @@ namespace Newtonsoft.Json.Linq CopyItemsTo(array, arrayIndex); } - bool ICollection.IsReadOnly - { - get { return false; } - } + bool ICollection.IsReadOnly => false; bool ICollection.Remove(JToken item) { @@ -986,15 +980,9 @@ namespace Newtonsoft.Json.Linq InsertItem(index, EnsureValue(value), false); } - bool IList.IsFixedSize - { - get { return false; } - } + bool IList.IsFixedSize => false; - bool IList.IsReadOnly - { - get { return false; } - } + bool IList.IsReadOnly => false; void IList.Remove(object value) { @@ -1008,8 +996,8 @@ namespace Newtonsoft.Json.Linq object IList.this[int index] { - get { return GetItem(index); } - set { SetItem(index, EnsureValue(value)); } + get => GetItem(index); + set => SetItem(index, EnsureValue(value)); } #endregion @@ -1023,15 +1011,9 @@ namespace Newtonsoft.Json.Linq /// Gets the count of child JSON tokens. /// /// The count of child JSON tokens. - public int Count - { - get { return ChildrenTokens.Count; } - } + public int Count => ChildrenTokens.Count; - bool ICollection.IsSynchronized - { - get { return false; } - } + bool ICollection.IsSynchronized => false; object ICollection.SyncRoot { @@ -1074,20 +1056,11 @@ namespace Newtonsoft.Json.Linq return newItem; } - bool IBindingList.AllowEdit - { - get { return true; } - } + bool IBindingList.AllowEdit => true; - bool IBindingList.AllowNew - { - get { return true; } - } + bool IBindingList.AllowNew => true; - bool IBindingList.AllowRemove - { - get { return true; } - } + bool IBindingList.AllowRemove => true; void IBindingList.ApplySort(PropertyDescriptor property, ListSortDirection direction) { @@ -1099,10 +1072,7 @@ namespace Newtonsoft.Json.Linq throw new NotSupportedException(); } - bool IBindingList.IsSorted - { - get { return false; } - } + bool IBindingList.IsSorted => false; void IBindingList.RemoveIndex(PropertyDescriptor property) { @@ -1113,30 +1083,15 @@ namespace Newtonsoft.Json.Linq throw new NotSupportedException(); } - ListSortDirection IBindingList.SortDirection - { - get { return ListSortDirection.Ascending; } - } + ListSortDirection IBindingList.SortDirection => ListSortDirection.Ascending; - PropertyDescriptor IBindingList.SortProperty - { - get { return null; } - } + PropertyDescriptor IBindingList.SortProperty => null; - bool IBindingList.SupportsChangeNotification - { - get { return true; } - } + bool IBindingList.SupportsChangeNotification => true; - bool IBindingList.SupportsSearching - { - get { return false; } - } + bool IBindingList.SupportsSearching => false; - bool IBindingList.SupportsSorting - { - get { return false; } - } + bool IBindingList.SupportsSorting => false; #endif #endregion diff --git a/Src/Newtonsoft.Json/Linq/JObject.cs b/Src/Newtonsoft.Json/Linq/JObject.cs index 4a981d71..551a39eb 100644 --- a/Src/Newtonsoft.Json/Linq/JObject.cs +++ b/Src/Newtonsoft.Json/Linq/JObject.cs @@ -65,10 +65,7 @@ namespace Newtonsoft.Json.Linq /// Gets the container's children tokens. /// /// The container's children tokens. - protected override IList ChildrenTokens - { - get { return _properties; } - } + protected override IList ChildrenTokens => _properties; /// /// Occurs when a property value changes. @@ -237,10 +234,7 @@ namespace Newtonsoft.Json.Linq /// Gets the node type for this . /// /// The type. - public override JTokenType Type - { - get { return JTokenType.Object; } - } + public override JTokenType Type => JTokenType.Object; /// /// Gets an of of this object's properties. @@ -558,11 +552,7 @@ namespace Newtonsoft.Json.Linq return _properties.Contains(key); } - ICollection IDictionary.Keys - { - // todo: make order of the collection returned match JObject order - get { return _properties.Keys; } - } + ICollection IDictionary.Keys => _properties.Keys; /// /// Removes the property with the specified name. @@ -600,14 +590,8 @@ namespace Newtonsoft.Json.Linq return true; } - ICollection IDictionary.Values - { - get - { - // todo: need to wrap _properties.Values with a collection to get the JProperty value - throw new NotImplementedException(); - } - } + ICollection IDictionary.Values => throw new NotImplementedException(); + #endregion #region ICollection> Members @@ -659,10 +643,7 @@ namespace Newtonsoft.Json.Linq } } - bool ICollection>.IsReadOnly - { - get { return false; } - } + bool ICollection>.IsReadOnly => false; bool ICollection>.Remove(KeyValuePair item) { diff --git a/Src/Newtonsoft.Json/Linq/JProperty.cs b/Src/Newtonsoft.Json/Linq/JProperty.cs index d6b1a6f9..0fab7be3 100644 --- a/Src/Newtonsoft.Json/Linq/JProperty.cs +++ b/Src/Newtonsoft.Json/Linq/JProperty.cs @@ -88,15 +88,9 @@ namespace Newtonsoft.Json.Linq return false; } - public int Count - { - get { return (_token != null) ? 1 : 0; } - } + public int Count => (_token != null) ? 1 : 0; - public bool IsReadOnly - { - get { return false; } - } + public bool IsReadOnly => false; public int IndexOf(JToken item) { @@ -121,7 +115,7 @@ namespace Newtonsoft.Json.Linq public JToken this[int index] { - get { return (index == 0) ? _token : null; } + get => (index == 0) ? _token : null; set { if (index == 0) @@ -140,10 +134,7 @@ namespace Newtonsoft.Json.Linq /// Gets the container's children tokens. /// /// The container's children tokens. - protected override IList ChildrenTokens - { - get { return _content; } - } + protected override IList ChildrenTokens => _content; /// /// Gets the property name. diff --git a/Src/Newtonsoft.Json/Linq/JPropertyDescriptor.cs b/Src/Newtonsoft.Json/Linq/JPropertyDescriptor.cs index eda6d39c..960b0725 100644 --- a/Src/Newtonsoft.Json/Linq/JPropertyDescriptor.cs +++ b/Src/Newtonsoft.Json/Linq/JPropertyDescriptor.cs @@ -115,10 +115,7 @@ namespace Newtonsoft.Json.Linq /// /// methods are invoked, the object specified might be an instance of this type. /// - public override Type ComponentType - { - get { return typeof(JObject); } - } + public override Type ComponentType => typeof(JObject); /// /// When overridden in a derived class, gets a value indicating whether this property is read-only. @@ -126,10 +123,7 @@ namespace Newtonsoft.Json.Linq /// /// true if the property is read-only; otherwise, false. /// - public override bool IsReadOnly - { - get { return false; } - } + public override bool IsReadOnly => false; /// /// When overridden in a derived class, gets the type of the property. @@ -137,10 +131,7 @@ namespace Newtonsoft.Json.Linq /// /// A that represents the type of the property. /// - public override Type PropertyType - { - get { return typeof(object); } - } + public override Type PropertyType => typeof(object); /// /// Gets the hash code for the name of the member. diff --git a/Src/Newtonsoft.Json/Linq/JToken.cs b/Src/Newtonsoft.Json/Linq/JToken.cs index 4ba4defd..07352836 100644 --- a/Src/Newtonsoft.Json/Linq/JToken.cs +++ b/Src/Newtonsoft.Json/Linq/JToken.cs @@ -164,8 +164,8 @@ namespace Newtonsoft.Json.Linq /// The that contains the next sibling token. public JToken Next { - get { return _next; } - internal set { _next = value; } + get => _next; + internal set => _next = value; } /// @@ -174,8 +174,8 @@ namespace Newtonsoft.Json.Linq /// The that contains the previous sibling token. public JToken Previous { - get { return _previous; } - internal set { _previous = value; } + get => _previous; + internal set => _previous = value; } /// @@ -319,8 +319,8 @@ namespace Newtonsoft.Json.Linq /// The with the specified key. public virtual JToken this[object key] { - get { throw new InvalidOperationException("Cannot access child value on {0}.".FormatWith(CultureInfo.InvariantCulture, GetType())); } - set { throw new InvalidOperationException("Cannot set child value on {0}.".FormatWith(CultureInfo.InvariantCulture, GetType())); } + get => throw new InvalidOperationException("Cannot access child value on {0}.".FormatWith(CultureInfo.InvariantCulture, GetType())); + set => throw new InvalidOperationException("Cannot set child value on {0}.".FormatWith(CultureInfo.InvariantCulture, GetType())); } /// @@ -341,19 +341,13 @@ namespace Newtonsoft.Json.Linq /// Get the first child token of this token. /// /// A containing the first child token of the . - public virtual JToken First - { - get { throw new InvalidOperationException("Cannot access child value on {0}.".FormatWith(CultureInfo.InvariantCulture, GetType())); } - } + public virtual JToken First => throw new InvalidOperationException("Cannot access child value on {0}.".FormatWith(CultureInfo.InvariantCulture, GetType())); /// /// Get the last child token of this token. /// /// A containing the last child token of the . - public virtual JToken Last - { - get { throw new InvalidOperationException("Cannot access child value on {0}.".FormatWith(CultureInfo.InvariantCulture, GetType())); } - } + public virtual JToken Last => throw new InvalidOperationException("Cannot access child value on {0}.".FormatWith(CultureInfo.InvariantCulture, GetType())); /// /// Returns a collection of the child tokens of this token, in document order. @@ -1879,10 +1873,7 @@ namespace Newtonsoft.Json.Linq internal abstract int GetDeepHashCode(); - IJEnumerable IJEnumerable.this[object key] - { - get { return this[key]; } - } + IJEnumerable IJEnumerable.this[object key] => this[key]; /// /// Creates a for this token. diff --git a/Src/Newtonsoft.Json/Linq/JTokenReader.cs b/Src/Newtonsoft.Json/Linq/JTokenReader.cs index 4ed06b27..16fba21e 100644 --- a/Src/Newtonsoft.Json/Linq/JTokenReader.cs +++ b/Src/Newtonsoft.Json/Linq/JTokenReader.cs @@ -41,10 +41,7 @@ namespace Newtonsoft.Json.Linq /// /// Gets the at the reader's current position. /// - public JToken CurrentToken - { - get { return _current; } - } + public JToken CurrentToken => _current; /// /// Initializes a new instance of the class. diff --git a/Src/Newtonsoft.Json/Linq/JTokenWriter.cs b/Src/Newtonsoft.Json/Linq/JTokenWriter.cs index 8750bc66..03f1d6b1 100644 --- a/Src/Newtonsoft.Json/Linq/JTokenWriter.cs +++ b/Src/Newtonsoft.Json/Linq/JTokenWriter.cs @@ -46,10 +46,7 @@ namespace Newtonsoft.Json.Linq /// /// Gets the at the writer's current position. /// - public JToken CurrentToken - { - get { return _current; } - } + public JToken CurrentToken => _current; /// /// Gets the token being written. diff --git a/Src/Newtonsoft.Json/Linq/JValue.cs b/Src/Newtonsoft.Json/Linq/JValue.cs index 3c58f116..8e6b76f7 100644 --- a/Src/Newtonsoft.Json/Linq/JValue.cs +++ b/Src/Newtonsoft.Json/Linq/JValue.cs @@ -214,10 +214,7 @@ namespace Newtonsoft.Json.Linq /// /// true if this token has child values; otherwise, false. /// - public override bool HasValues - { - get { return false; } - } + public override bool HasValues => false; #if HAVE_BIG_INTEGER private static int CompareBigInteger(BigInteger i1, object i2) @@ -695,10 +692,7 @@ namespace Newtonsoft.Json.Linq /// Gets the node type for this . /// /// The type. - public override JTokenType Type - { - get { return _valueType; } - } + public override JTokenType Type => _valueType; /// /// Gets or sets the underlying token value. @@ -706,7 +700,7 @@ namespace Newtonsoft.Json.Linq /// The underlying token value. public object Value { - get { return _value; } + get => _value; set { Type currentType = _value?.GetType(); diff --git a/Src/Newtonsoft.Json/Linq/JsonLoadSettings.cs b/Src/Newtonsoft.Json/Linq/JsonLoadSettings.cs index de4aadd2..3e392c83 100644 --- a/Src/Newtonsoft.Json/Linq/JsonLoadSettings.cs +++ b/Src/Newtonsoft.Json/Linq/JsonLoadSettings.cs @@ -25,7 +25,7 @@ namespace Newtonsoft.Json.Linq /// The JSON comment handling. public CommentHandling CommentHandling { - get { return _commentHandling; } + get => _commentHandling; set { if (value < CommentHandling.Ignore || value > CommentHandling.Load) @@ -43,7 +43,7 @@ namespace Newtonsoft.Json.Linq /// The JSON line info handling. public LineInfoHandling LineInfoHandling { - get { return _lineInfoHandling; } + get => _lineInfoHandling; set { if (value < LineInfoHandling.Ignore || value > LineInfoHandling.Load) diff --git a/Src/Newtonsoft.Json/Linq/JsonMergeSettings.cs b/Src/Newtonsoft.Json/Linq/JsonMergeSettings.cs index 5ef2c669..b3d94332 100644 --- a/Src/Newtonsoft.Json/Linq/JsonMergeSettings.cs +++ b/Src/Newtonsoft.Json/Linq/JsonMergeSettings.cs @@ -16,7 +16,7 @@ namespace Newtonsoft.Json.Linq /// The method used when merging JSON arrays. public MergeArrayHandling MergeArrayHandling { - get { return _mergeArrayHandling; } + get => _mergeArrayHandling; set { if (value < MergeArrayHandling.Concat || value > MergeArrayHandling.Merge) @@ -34,7 +34,7 @@ namespace Newtonsoft.Json.Linq /// How null value properties are merged. public MergeNullValueHandling MergeNullValueHandling { - get { return _mergeNullValueHandling; } + get => _mergeNullValueHandling; set { if (value < MergeNullValueHandling.Ignore || value > MergeNullValueHandling.Merge) diff --git a/Src/Newtonsoft.Json/Schema/JsonSchema.cs b/Src/Newtonsoft.Json/Schema/JsonSchema.cs index db2dbfa5..f032e8ea 100644 --- a/Src/Newtonsoft.Json/Schema/JsonSchema.cs +++ b/Src/Newtonsoft.Json/Schema/JsonSchema.cs @@ -243,10 +243,7 @@ namespace Newtonsoft.Json.Schema private readonly string _internalId = Guid.NewGuid().ToString("N"); - internal string InternalId - { - get { return _internalId; } - } + internal string InternalId => _internalId; // if this is set then this schema instance is just a deferred reference // and will be replaced when the schema reference is resolved diff --git a/Src/Newtonsoft.Json/Schema/JsonSchemaBuilder.cs b/Src/Newtonsoft.Json/Schema/JsonSchemaBuilder.cs index d39f3592..d4989f00 100644 --- a/Src/Newtonsoft.Json/Schema/JsonSchemaBuilder.cs +++ b/Src/Newtonsoft.Json/Schema/JsonSchemaBuilder.cs @@ -70,10 +70,7 @@ namespace Newtonsoft.Json.Schema return poppedSchema; } - private JsonSchema CurrentSchema - { - get { return _currentSchema; } - } + private JsonSchema CurrentSchema => _currentSchema; internal JsonSchema Read(JsonReader reader) { diff --git a/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs b/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs index b19c7e07..17384209 100644 --- a/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs +++ b/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs @@ -72,7 +72,7 @@ namespace Newtonsoft.Json.Schema return _contractResolver; } - set { _contractResolver = value; } + set => _contractResolver = value; } private class TypeSchema @@ -94,10 +94,7 @@ namespace Newtonsoft.Json.Schema private readonly IList _stack = new List(); private JsonSchema _currentSchema; - private JsonSchema CurrentSchema - { - get { return _currentSchema; } - } + private JsonSchema CurrentSchema => _currentSchema; private void Push(TypeSchema typeSchema) { diff --git a/Src/Newtonsoft.Json/Schema/ValidationEventArgs.cs b/Src/Newtonsoft.Json/Schema/ValidationEventArgs.cs index b1444598..11395485 100644 --- a/Src/Newtonsoft.Json/Schema/ValidationEventArgs.cs +++ b/Src/Newtonsoft.Json/Schema/ValidationEventArgs.cs @@ -51,27 +51,18 @@ namespace Newtonsoft.Json.Schema /// Gets the associated with the validation error. /// /// The JsonSchemaException associated with the validation error. - public JsonSchemaException Exception - { - get { return _ex; } - } + public JsonSchemaException Exception => _ex; /// /// Gets the path of the JSON location where the validation error occurred. /// /// The path of the JSON location where the validation error occurred. - public string Path - { - get { return _ex.Path; } - } + public string Path => _ex.Path; /// /// Gets the text description corresponding to the validation error. /// /// The text description. - public string Message - { - get { return _ex.Message; } - } + public string Message => _ex.Message; } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs index ede251e0..22e558ee 100644 --- a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs +++ b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs @@ -62,10 +62,7 @@ namespace Newtonsoft.Json.Serialization private static readonly IContractResolver _instance = new DefaultContractResolver(); // Json.NET Schema requires a property - internal static IContractResolver Instance - { - get { return _instance; } - } + internal static IContractResolver Instance => _instance; private static readonly JsonConverter[] BuiltInConverters = { @@ -104,10 +101,7 @@ namespace Newtonsoft.Json.Serialization /// /// true if using dynamic code generation; otherwise, false. /// - public bool DynamicCodeGeneration - { - get { return JsonTypeReflector.DynamicCodeGeneration; } - } + public bool DynamicCodeGeneration => JsonTypeReflector.DynamicCodeGeneration; #if !PORTABLE /// diff --git a/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs b/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs index 0c22e312..66b5c011 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs @@ -91,7 +91,7 @@ namespace Newtonsoft.Json.Serialization /// The function used to create the object. public ObjectConstructor OverrideCreator { - get { return _overrideCreator; } + get => _overrideCreator; set { _overrideCreator = value; @@ -106,10 +106,7 @@ namespace Newtonsoft.Json.Serialization /// true if the creator has a parameter with the collection values; otherwise, false. public bool HasParameterizedCreator { get; set; } - internal bool HasParameterizedCreatorInternal - { - get { return (HasParameterizedCreator || _parameterizedCreator != null || _parameterizedConstructor != null); } - } + internal bool HasParameterizedCreatorInternal => (HasParameterizedCreator || _parameterizedCreator != null || _parameterizedConstructor != null); /// /// Initializes a new instance of the class. diff --git a/Src/Newtonsoft.Json/Serialization/JsonContainerContract.cs b/Src/Newtonsoft.Json/Serialization/JsonContainerContract.cs index 0c2dff58..f1e7796b 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonContainerContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonContainerContract.cs @@ -48,7 +48,7 @@ namespace Newtonsoft.Json.Serialization // will be null for containers that don't have an item type (e.g. IList) or for complex objects internal JsonContract ItemContract { - get { return _itemContract; } + get => _itemContract; set { _itemContract = value; @@ -64,10 +64,7 @@ namespace Newtonsoft.Json.Serialization } // the final (i.e. can't be inherited from like a sealed class or valuetype) item contract - internal JsonContract FinalItemContract - { - get { return _finalItemContract; } - } + internal JsonContract FinalItemContract => _finalItemContract; /// /// Gets or sets the default collection items . diff --git a/Src/Newtonsoft.Json/Serialization/JsonContract.cs b/Src/Newtonsoft.Json/Serialization/JsonContract.cs index fb957095..ddac8cc2 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonContract.cs @@ -109,7 +109,7 @@ namespace Newtonsoft.Json.Serialization /// The type created during deserialization. public Type CreatedType { - get { return _createdType; } + get => _createdType; set { _createdType = value; diff --git a/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs b/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs index e50981ff..1731a8d7 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs @@ -94,8 +94,8 @@ namespace Newtonsoft.Json.Serialization /// The function used to create the object. public ObjectConstructor OverrideCreator { - get { return _overrideCreator; } - set { _overrideCreator = value; } + get => _overrideCreator; + set => _overrideCreator = value; } /// @@ -104,10 +104,7 @@ namespace Newtonsoft.Json.Serialization /// true if the creator has a parameter with the dictionary values; otherwise, false. public bool HasParameterizedCreator { get; set; } - internal bool HasParameterizedCreatorInternal - { - get { return (HasParameterizedCreator || _parameterizedCreator != null || _parameterizedConstructor != null); } - } + internal bool HasParameterizedCreatorInternal => (HasParameterizedCreator || _parameterizedCreator != null || _parameterizedConstructor != null); /// /// Initializes a new instance of the class. diff --git a/Src/Newtonsoft.Json/Serialization/JsonObjectContract.cs b/Src/Newtonsoft.Json/Serialization/JsonObjectContract.cs index 082a3625..c80c01b2 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonObjectContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonObjectContract.cs @@ -81,14 +81,14 @@ namespace Newtonsoft.Json.Serialization /// The function used to create the object. public ObjectConstructor OverrideCreator { - get { return _overrideCreator; } - set { _overrideCreator = value; } + get => _overrideCreator; + set => _overrideCreator = value; } internal ObjectConstructor ParameterizedCreator { - get { return _parameterizedCreator; } - set { _parameterizedCreator = value; } + get => _parameterizedCreator; + set => _parameterizedCreator = value; } /// @@ -106,7 +106,7 @@ namespace Newtonsoft.Json.Serialization /// public Type ExtensionDataValueType { - get { return _extensionDataValueType; } + get => _extensionDataValueType; set { _extensionDataValueType = value; diff --git a/Src/Newtonsoft.Json/Serialization/JsonPrimitiveContract.cs b/Src/Newtonsoft.Json/Serialization/JsonPrimitiveContract.cs index 9c32f960..6d662de5 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonPrimitiveContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonPrimitiveContract.cs @@ -48,8 +48,7 @@ namespace Newtonsoft.Json.Serialization TypeCode = ConvertUtils.GetTypeCode(underlyingType); IsReadOnlyOrFixedSize = true; - ReadType readType; - if (ReadTypeMap.TryGetValue(NonNullableUnderlyingType, out readType)) + if (ReadTypeMap.TryGetValue(NonNullableUnderlyingType, out ReadType readType)) { InternalReadType = readType; } diff --git a/Src/Newtonsoft.Json/Serialization/JsonProperty.cs b/Src/Newtonsoft.Json/Serialization/JsonProperty.cs index 886abec7..1c9b727c 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonProperty.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonProperty.cs @@ -56,7 +56,7 @@ namespace Newtonsoft.Json.Serialization /// The name of the property. public string PropertyName { - get { return _propertyName; } + get => _propertyName; set { _propertyName = value; @@ -100,7 +100,7 @@ namespace Newtonsoft.Json.Serialization /// The type of the property. public Type PropertyType { - get { return _propertyType; } + get => _propertyType; set { if (_propertyType != value) @@ -125,8 +125,8 @@ namespace Newtonsoft.Json.Serialization [Obsolete("MemberConverter is obsolete. Use Converter instead.")] public JsonConverter MemberConverter { - get { return Converter; } - set { Converter = value; } + get => Converter; + set => Converter = value; } /// @@ -197,8 +197,8 @@ namespace Newtonsoft.Json.Serialization /// A value indicating whether this is required. public Required Required { - get { return _required ?? Required.Default; } - set { _required = value; } + get => _required ?? Required.Default; + set => _required = value; } /// diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerProxy.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerProxy.cs index bbc075a9..a5ff8c05 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerProxy.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerProxy.cs @@ -40,189 +40,186 @@ namespace Newtonsoft.Json.Serialization public override event EventHandler Error { - add { _serializer.Error += value; } - remove { _serializer.Error -= value; } + add => _serializer.Error += value; + remove => _serializer.Error -= value; } public override IReferenceResolver ReferenceResolver { - get { return _serializer.ReferenceResolver; } - set { _serializer.ReferenceResolver = value; } + get => _serializer.ReferenceResolver; + set => _serializer.ReferenceResolver = value; } public override ITraceWriter TraceWriter { - get { return _serializer.TraceWriter; } - set { _serializer.TraceWriter = value; } + get => _serializer.TraceWriter; + set => _serializer.TraceWriter = value; } public override IEqualityComparer EqualityComparer { - get { return _serializer.EqualityComparer; } - set { _serializer.EqualityComparer = value; } + get => _serializer.EqualityComparer; + set => _serializer.EqualityComparer = value; } - public override JsonConverterCollection Converters - { - get { return _serializer.Converters; } - } + public override JsonConverterCollection Converters => _serializer.Converters; public override DefaultValueHandling DefaultValueHandling { - get { return _serializer.DefaultValueHandling; } - set { _serializer.DefaultValueHandling = value; } + get => _serializer.DefaultValueHandling; + set => _serializer.DefaultValueHandling = value; } public override IContractResolver ContractResolver { - get { return _serializer.ContractResolver; } - set { _serializer.ContractResolver = value; } + get => _serializer.ContractResolver; + set => _serializer.ContractResolver = value; } public override MissingMemberHandling MissingMemberHandling { - get { return _serializer.MissingMemberHandling; } - set { _serializer.MissingMemberHandling = value; } + get => _serializer.MissingMemberHandling; + set => _serializer.MissingMemberHandling = value; } public override NullValueHandling NullValueHandling { - get { return _serializer.NullValueHandling; } - set { _serializer.NullValueHandling = value; } + get => _serializer.NullValueHandling; + set => _serializer.NullValueHandling = value; } public override ObjectCreationHandling ObjectCreationHandling { - get { return _serializer.ObjectCreationHandling; } - set { _serializer.ObjectCreationHandling = value; } + get => _serializer.ObjectCreationHandling; + set => _serializer.ObjectCreationHandling = value; } public override ReferenceLoopHandling ReferenceLoopHandling { - get { return _serializer.ReferenceLoopHandling; } - set { _serializer.ReferenceLoopHandling = value; } + get => _serializer.ReferenceLoopHandling; + set => _serializer.ReferenceLoopHandling = value; } public override PreserveReferencesHandling PreserveReferencesHandling { - get { return _serializer.PreserveReferencesHandling; } - set { _serializer.PreserveReferencesHandling = value; } + get => _serializer.PreserveReferencesHandling; + set => _serializer.PreserveReferencesHandling = value; } public override TypeNameHandling TypeNameHandling { - get { return _serializer.TypeNameHandling; } - set { _serializer.TypeNameHandling = value; } + get => _serializer.TypeNameHandling; + set => _serializer.TypeNameHandling = value; } public override MetadataPropertyHandling MetadataPropertyHandling { - get { return _serializer.MetadataPropertyHandling; } - set { _serializer.MetadataPropertyHandling = value; } + get => _serializer.MetadataPropertyHandling; + set => _serializer.MetadataPropertyHandling = value; } [Obsolete("TypeNameAssemblyFormat is obsolete. Use TypeNameAssemblyFormatHandling instead.")] public override FormatterAssemblyStyle TypeNameAssemblyFormat { - get { return _serializer.TypeNameAssemblyFormat; } - set { _serializer.TypeNameAssemblyFormat = value; } + get => _serializer.TypeNameAssemblyFormat; + set => _serializer.TypeNameAssemblyFormat = value; } public override TypeNameAssemblyFormatHandling TypeNameAssemblyFormatHandling { - get { return _serializer.TypeNameAssemblyFormatHandling; } - set { _serializer.TypeNameAssemblyFormatHandling = value; } + get => _serializer.TypeNameAssemblyFormatHandling; + set => _serializer.TypeNameAssemblyFormatHandling = value; } public override ConstructorHandling ConstructorHandling { - get { return _serializer.ConstructorHandling; } - set { _serializer.ConstructorHandling = value; } + get => _serializer.ConstructorHandling; + set => _serializer.ConstructorHandling = value; } [Obsolete("Binder is obsolete. Use SerializationBinder instead.")] public override SerializationBinder Binder { - get { return _serializer.Binder; } - set { _serializer.Binder = value; } + get => _serializer.Binder; + set => _serializer.Binder = value; } public override ISerializationBinder SerializationBinder { - get { return _serializer.SerializationBinder; } - set { _serializer.SerializationBinder = value; } + get => _serializer.SerializationBinder; + set => _serializer.SerializationBinder = value; } public override StreamingContext Context { - get { return _serializer.Context; } - set { _serializer.Context = value; } + get => _serializer.Context; + set => _serializer.Context = value; } public override Formatting Formatting { - get { return _serializer.Formatting; } - set { _serializer.Formatting = value; } + get => _serializer.Formatting; + set => _serializer.Formatting = value; } public override DateFormatHandling DateFormatHandling { - get { return _serializer.DateFormatHandling; } - set { _serializer.DateFormatHandling = value; } + get => _serializer.DateFormatHandling; + set => _serializer.DateFormatHandling = value; } public override DateTimeZoneHandling DateTimeZoneHandling { - get { return _serializer.DateTimeZoneHandling; } - set { _serializer.DateTimeZoneHandling = value; } + get => _serializer.DateTimeZoneHandling; + set => _serializer.DateTimeZoneHandling = value; } public override DateParseHandling DateParseHandling { - get { return _serializer.DateParseHandling; } - set { _serializer.DateParseHandling = value; } + get => _serializer.DateParseHandling; + set => _serializer.DateParseHandling = value; } public override FloatFormatHandling FloatFormatHandling { - get { return _serializer.FloatFormatHandling; } - set { _serializer.FloatFormatHandling = value; } + get => _serializer.FloatFormatHandling; + set => _serializer.FloatFormatHandling = value; } public override FloatParseHandling FloatParseHandling { - get { return _serializer.FloatParseHandling; } - set { _serializer.FloatParseHandling = value; } + get => _serializer.FloatParseHandling; + set => _serializer.FloatParseHandling = value; } public override StringEscapeHandling StringEscapeHandling { - get { return _serializer.StringEscapeHandling; } - set { _serializer.StringEscapeHandling = value; } + get => _serializer.StringEscapeHandling; + set => _serializer.StringEscapeHandling = value; } public override string DateFormatString { - get { return _serializer.DateFormatString; } - set { _serializer.DateFormatString = value; } + get => _serializer.DateFormatString; + set => _serializer.DateFormatString = value; } public override CultureInfo Culture { - get { return _serializer.Culture; } - set { _serializer.Culture = value; } + get => _serializer.Culture; + set => _serializer.Culture = value; } public override int? MaxDepth { - get { return _serializer.MaxDepth; } - set { _serializer.MaxDepth = value; } + get => _serializer.MaxDepth; + set => _serializer.MaxDepth = value; } public override bool CheckAdditionalContent { - get { return _serializer.CheckAdditionalContent; } - set { _serializer.CheckAdditionalContent = value; } + get => _serializer.CheckAdditionalContent; + set => _serializer.CheckAdditionalContent = value; } internal JsonSerializerInternalBase GetInternalSerializer() diff --git a/Src/Newtonsoft.Json/Serialization/TraceJsonReader.cs b/Src/Newtonsoft.Json/Serialization/TraceJsonReader.cs index 47d2a9b9..d4885d9b 100644 --- a/Src/Newtonsoft.Json/Serialization/TraceJsonReader.cs +++ b/Src/Newtonsoft.Json/Serialization/TraceJsonReader.cs @@ -99,36 +99,21 @@ namespace Newtonsoft.Json.Serialization _textWriter.WriteToken(_innerReader, false, false, true); } - public override int Depth - { - get { return _innerReader.Depth; } - } + public override int Depth => _innerReader.Depth; - public override string Path - { - get { return _innerReader.Path; } - } + public override string Path => _innerReader.Path; public override char QuoteChar { - get { return _innerReader.QuoteChar; } - protected internal set { _innerReader.QuoteChar = value; } + get => _innerReader.QuoteChar; + protected internal set => _innerReader.QuoteChar = value; } - public override JsonToken TokenType - { - get { return _innerReader.TokenType; } - } + public override JsonToken TokenType => _innerReader.TokenType; - public override object Value - { - get { return _innerReader.Value; } - } + public override object Value => _innerReader.Value; - public override Type ValueType - { - get { return _innerReader.ValueType; } - } + public override Type ValueType => _innerReader.ValueType; public override void Close() { diff --git a/Src/Newtonsoft.Json/Utilities/CollectionWrapper.cs b/Src/Newtonsoft.Json/Utilities/CollectionWrapper.cs index 39c17c6c..55d17fce 100644 --- a/Src/Newtonsoft.Json/Utilities/CollectionWrapper.cs +++ b/Src/Newtonsoft.Json/Utilities/CollectionWrapper.cs @@ -283,10 +283,7 @@ namespace Newtonsoft.Json.Utilities CopyTo((T[])array, arrayIndex); } - bool ICollection.IsSynchronized - { - get { return false; } - } + bool ICollection.IsSynchronized => false; object ICollection.SyncRoot { @@ -319,9 +316,6 @@ namespace Newtonsoft.Json.Utilities return true; } - public object UnderlyingCollection - { - get { return (object)_genericCollection ?? _list; } - } + public object UnderlyingCollection => (object)_genericCollection ?? _list; } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs b/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs index 9eca0548..05977bd5 100644 --- a/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs +++ b/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs @@ -492,25 +492,13 @@ namespace Newtonsoft.Json.Utilities _e = e; } - public DictionaryEntry Entry - { - get { return (DictionaryEntry)Current; } - } + public DictionaryEntry Entry => (DictionaryEntry)Current; - public object Key - { - get { return Entry.Key; } - } + public object Key => Entry.Key; - public object Value - { - get { return Entry.Value; } - } + public object Value => Entry.Value; - public object Current - { - get { return new DictionaryEntry(_e.Current.Key, _e.Current.Value); } - } + public object Current => new DictionaryEntry(_e.Current.Key, _e.Current.Value); public bool MoveNext() { diff --git a/Src/Newtonsoft.Json/Utilities/DynamicReflectionDelegateFactory.cs b/Src/Newtonsoft.Json/Utilities/DynamicReflectionDelegateFactory.cs index 6da17b37..83888089 100644 --- a/Src/Newtonsoft.Json/Utilities/DynamicReflectionDelegateFactory.cs +++ b/Src/Newtonsoft.Json/Utilities/DynamicReflectionDelegateFactory.cs @@ -40,10 +40,7 @@ namespace Newtonsoft.Json.Utilities { private static readonly DynamicReflectionDelegateFactory _instance = new DynamicReflectionDelegateFactory(); - internal static DynamicReflectionDelegateFactory Instance - { - get { return _instance; } - } + internal static DynamicReflectionDelegateFactory Instance => _instance; private static DynamicMethod CreateDynamicMethod(string name, Type returnType, Type[] parameterTypes, Type owner) { diff --git a/Src/Newtonsoft.Json/Utilities/EnumValue.cs b/Src/Newtonsoft.Json/Utilities/EnumValue.cs index c672ead8..909cd1a4 100644 --- a/Src/Newtonsoft.Json/Utilities/EnumValue.cs +++ b/Src/Newtonsoft.Json/Utilities/EnumValue.cs @@ -30,15 +30,9 @@ namespace Newtonsoft.Json.Utilities private readonly string _name; private readonly T _value; - public string Name - { - get { return _name; } - } + public string Name => _name; - public T Value - { - get { return _value; } - } + public T Value => _value; public EnumValue(string name, T value) { diff --git a/Src/Newtonsoft.Json/Utilities/LateBoundReflectionDelegateFactory.cs b/Src/Newtonsoft.Json/Utilities/LateBoundReflectionDelegateFactory.cs index 2c01a6a1..ddccd316 100644 --- a/Src/Newtonsoft.Json/Utilities/LateBoundReflectionDelegateFactory.cs +++ b/Src/Newtonsoft.Json/Utilities/LateBoundReflectionDelegateFactory.cs @@ -37,10 +37,7 @@ namespace Newtonsoft.Json.Utilities { private static readonly LateBoundReflectionDelegateFactory _instance = new LateBoundReflectionDelegateFactory(); - internal static ReflectionDelegateFactory Instance - { - get { return _instance; } - } + internal static ReflectionDelegateFactory Instance => _instance; public override ObjectConstructor CreateParameterizedConstructor(MethodBase method) { diff --git a/Src/Newtonsoft.Json/Utilities/LinqBridge.cs b/Src/Newtonsoft.Json/Utilities/LinqBridge.cs index c10d7c3e..be82784a 100644 --- a/Src/Newtonsoft.Json/Utilities/LinqBridge.cs +++ b/Src/Newtonsoft.Json/Utilities/LinqBridge.cs @@ -2832,12 +2832,9 @@ namespace Newtonsoft.Json.Utilities.LinqBridge /// Gets the number of key/value collection pairs in the . /// - public int Count - { - get { return _map.Count; } - } + public int Count => _map.Count; - /// + /// /// Gets the collection of values indexed by the specified key. /// diff --git a/Src/Newtonsoft.Json/Utilities/StringBuffer.cs b/Src/Newtonsoft.Json/Utilities/StringBuffer.cs index 520da4f1..8c9dcf47 100644 --- a/Src/Newtonsoft.Json/Utilities/StringBuffer.cs +++ b/Src/Newtonsoft.Json/Utilities/StringBuffer.cs @@ -37,14 +37,11 @@ namespace Newtonsoft.Json.Utilities public int Position { - get { return _position; } - set { _position = value; } + get => _position; + set => _position = value; } - public bool IsEmpty - { - get { return _buffer == null; } - } + public bool IsEmpty => _buffer == null; public StringBuffer(IArrayPool bufferPool, int initalSize) : this(BufferUtils.RentBuffer(bufferPool, initalSize)) { @@ -114,9 +111,6 @@ namespace Newtonsoft.Json.Utilities return new string(_buffer, start, length); } - public char[] InternalBuffer - { - get { return _buffer; } - } + public char[] InternalBuffer => _buffer; } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Utilities/StringReference.cs b/Src/Newtonsoft.Json/Utilities/StringReference.cs index 5028a41c..49d257c6 100644 --- a/Src/Newtonsoft.Json/Utilities/StringReference.cs +++ b/Src/Newtonsoft.Json/Utilities/StringReference.cs @@ -33,25 +33,13 @@ namespace Newtonsoft.Json.Utilities private readonly int _startIndex; private readonly int _length; - public char this[int i] - { - get { return _chars[i]; } - } + public char this[int i] => _chars[i]; - public char[] Chars - { - get { return _chars; } - } + public char[] Chars => _chars; - public int StartIndex - { - get { return _startIndex; } - } + public int StartIndex => _startIndex; - public int Length - { - get { return _length; } - } + public int Length => _length; public StringReference(char[] chars, int startIndex, int length) {