From b59b3028c6ffc157da69d11a7ede73ff71489943 Mon Sep 17 00:00:00 2001 From: oneRain Date: Wed, 31 Mar 2021 11:49:13 +0800 Subject: [PATCH] chore: Newtonsoft.Json.AOT 12.0.201 --- Libs/Newtonsoft.Json.AOT/JsonConvert.cs | 22 +++-- Libs/Newtonsoft.Json.AOT/JsonConverter.cs | 12 ++- Libs/Newtonsoft.Json.AOT/JsonReader.cs | 3 - Libs/Newtonsoft.Json.AOT/JsonSerializer.cs | 9 +- .../JsonSerializerSettings.cs | 5 +- Libs/Newtonsoft.Json.AOT/JsonWriter.cs | 13 ++- .../LC.Newtonsoft.Json.AOT.csproj | 30 +++++-- Libs/Newtonsoft.Json.AOT/Linq/Extensions.cs | 21 ++--- Libs/Newtonsoft.Json.AOT/Linq/JContainer.cs | 31 +++---- Libs/Newtonsoft.Json.AOT/Linq/JEnumerable.cs | 2 +- Libs/Newtonsoft.Json.AOT/Linq/JObject.cs | 6 +- Libs/Newtonsoft.Json.AOT/Linq/JProperty.cs | 6 +- Libs/Newtonsoft.Json.AOT/Linq/JToken.cs | 86 +++++-------------- Libs/Newtonsoft.Json.AOT/Linq/JTokenWriter.cs | 15 ++-- Libs/Newtonsoft.Json.AOT/Linq/JValue.cs | 3 +- .../Linq/JsonPath/ArrayIndexFilter.cs | 6 +- .../Linq/JsonPath/ArrayMultipleIndexFilter.cs | 4 +- .../Linq/JsonPath/ArraySliceFilter.cs | 6 +- .../Linq/JsonPath/FieldFilter.cs | 6 +- .../Linq/JsonPath/FieldMultipleFilter.cs | 6 +- .../Linq/JsonPath/JPath.cs | 8 +- .../Linq/JsonPath/PathFilter.cs | 10 +-- .../Linq/JsonPath/QueryExpression.cs | 31 +++---- .../Linq/JsonPath/QueryFilter.cs | 4 +- .../Linq/JsonPath/QueryScanFilter.cs | 6 +- .../Linq/JsonPath/RootFilter.cs | 2 +- .../Linq/JsonPath/ScanFilter.cs | 2 +- .../Linq/JsonPath/ScanMultipleFilter.cs | 2 +- .../Linq/JsonSelectSettings.cs | 28 ------ Libs/Newtonsoft.Json.AOT/Resources/link.xml | 18 ---- .../Serialization/JsonDictionaryContract.cs | 24 +++--- .../JsonSerializerInternalReader.cs | 70 ++++++--------- .../JsonSerializerInternalWriter.cs | 8 +- .../Utilities/AsyncUtils.cs | 4 +- .../Utilities/DateTimeUtils.cs | 12 +-- .../Utilities/DictionaryWrapper.cs | 8 +- .../Utilities/JavaScriptUtils.cs | 2 +- .../Utilities/StringUtils.cs | 2 +- csharp-sdk.sln | 14 +-- 39 files changed, 214 insertions(+), 333 deletions(-) delete mode 100644 Libs/Newtonsoft.Json.AOT/Linq/JsonSelectSettings.cs delete mode 100644 Libs/Newtonsoft.Json.AOT/Resources/link.xml diff --git a/Libs/Newtonsoft.Json.AOT/JsonConvert.cs b/Libs/Newtonsoft.Json.AOT/JsonConvert.cs index 639a169..1cda368 100644 --- a/Libs/Newtonsoft.Json.AOT/JsonConvert.cs +++ b/Libs/Newtonsoft.Json.AOT/JsonConvert.cs @@ -587,7 +587,7 @@ namespace LC.Newtonsoft.Json /// A JSON string representation of the object. /// [DebuggerStepThrough] - public static string SerializeObject(object? value, JsonSerializerSettings? settings) + public static string SerializeObject(object? value, JsonSerializerSettings settings) { return SerializeObject(value, null, settings); } @@ -715,7 +715,7 @@ namespace LC.Newtonsoft.Json /// The JSON to deserialize. /// The deserialized object from the JSON string. [DebuggerStepThrough] - public static T? DeserializeObject(string value) + public static T DeserializeObject(string value) { return DeserializeObject(value, (JsonSerializerSettings?)null); } @@ -732,7 +732,7 @@ namespace LC.Newtonsoft.Json /// The anonymous type object. /// The deserialized anonymous type from the JSON string. [DebuggerStepThrough] - public static T? DeserializeAnonymousType(string value, T anonymousTypeObject) + public static T DeserializeAnonymousType(string value, T anonymousTypeObject) { return DeserializeObject(value); } @@ -753,7 +753,7 @@ namespace LC.Newtonsoft.Json /// /// The deserialized anonymous type from the JSON string. [DebuggerStepThrough] - public static T? DeserializeAnonymousType(string value, T anonymousTypeObject, JsonSerializerSettings settings) + public static T DeserializeAnonymousType(string value, T anonymousTypeObject, JsonSerializerSettings settings) { return DeserializeObject(value, settings); } @@ -766,9 +766,12 @@ namespace LC.Newtonsoft.Json /// Converters to use while deserializing. /// The deserialized object from the JSON string. [DebuggerStepThrough] - public static T? DeserializeObject(string value, params JsonConverter[] converters) + [return: MaybeNull] + public static T DeserializeObject(string value, params JsonConverter[] converters) { - return (T?)DeserializeObject(value, typeof(T), converters); +#pragma warning disable CS8601 // Possible null reference assignment. + return (T)DeserializeObject(value, typeof(T), converters); +#pragma warning restore CS8601 // Possible null reference assignment. } /// @@ -782,9 +785,12 @@ namespace LC.Newtonsoft.Json /// /// The deserialized object from the JSON string. [DebuggerStepThrough] - public static T? DeserializeObject(string value, JsonSerializerSettings? settings) + [return: MaybeNull] + public static T DeserializeObject(string value, JsonSerializerSettings? settings) { - return (T?)DeserializeObject(value, typeof(T), settings); +#pragma warning disable CS8601 // Possible null reference assignment. + return (T)DeserializeObject(value, typeof(T), settings); +#pragma warning restore CS8601 // Possible null reference assignment. } /// diff --git a/Libs/Newtonsoft.Json.AOT/JsonConverter.cs b/Libs/Newtonsoft.Json.AOT/JsonConverter.cs index 9f5ff5d..3361faa 100644 --- a/Libs/Newtonsoft.Json.AOT/JsonConverter.cs +++ b/Libs/Newtonsoft.Json.AOT/JsonConverter.cs @@ -94,7 +94,9 @@ namespace LC.Newtonsoft.Json { throw new JsonSerializationException("Converter cannot write specified value to JSON. {0} is required.".FormatWith(CultureInfo.InvariantCulture, typeof(T))); } - WriteJson(writer, (T?)value, serializer); +#pragma warning disable CS8601 // Possible null reference assignment. + WriteJson(writer, (T)value, serializer); +#pragma warning restore CS8601 // Possible null reference assignment. } /// @@ -103,7 +105,7 @@ namespace LC.Newtonsoft.Json /// The to write to. /// The value. /// The calling serializer. - public abstract void WriteJson(JsonWriter writer, T? value, JsonSerializer serializer); + public abstract void WriteJson(JsonWriter writer, [AllowNull]T value, JsonSerializer serializer); /// /// Reads the JSON representation of the object. @@ -120,7 +122,9 @@ namespace LC.Newtonsoft.Json { throw new JsonSerializationException("Converter cannot read JSON with the specified existing value. {0} is required.".FormatWith(CultureInfo.InvariantCulture, typeof(T))); } - return ReadJson(reader, objectType, existingIsNull ? default : (T?)existingValue, !existingIsNull, serializer); +#pragma warning disable CS8601 // Possible null reference assignment. + return ReadJson(reader, objectType, existingIsNull ? default : (T)existingValue, !existingIsNull, serializer); +#pragma warning restore CS8601 // Possible null reference assignment. } /// @@ -132,7 +136,7 @@ namespace LC.Newtonsoft.Json /// The existing value has a value. /// The calling serializer. /// The object value. - public abstract T? ReadJson(JsonReader reader, Type objectType, T? existingValue, bool hasExistingValue, JsonSerializer serializer); + public abstract T ReadJson(JsonReader reader, Type objectType, [AllowNull]T existingValue, bool hasExistingValue, JsonSerializer serializer); /// /// Determines whether this instance can convert the specified object type. diff --git a/Libs/Newtonsoft.Json.AOT/JsonReader.cs b/Libs/Newtonsoft.Json.AOT/JsonReader.cs index bea7c47..2e91763 100644 --- a/Libs/Newtonsoft.Json.AOT/JsonReader.cs +++ b/Libs/Newtonsoft.Json.AOT/JsonReader.cs @@ -227,8 +227,6 @@ namespace LC.Newtonsoft.Json /// /// Gets or sets the maximum depth allowed when reading JSON. Reading past this depth will throw a . - /// A null value means there is no maximum. - /// The default value is 128. /// public int? MaxDepth { @@ -329,7 +327,6 @@ namespace LC.Newtonsoft.Json _dateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind; _dateParseHandling = DateParseHandling.DateTime; _floatParseHandling = FloatParseHandling.Double; - _maxDepth = 64; CloseInput = true; } diff --git a/Libs/Newtonsoft.Json.AOT/JsonSerializer.cs b/Libs/Newtonsoft.Json.AOT/JsonSerializer.cs index aab727f..e8bdb90 100644 --- a/Libs/Newtonsoft.Json.AOT/JsonSerializer.cs +++ b/Libs/Newtonsoft.Json.AOT/JsonSerializer.cs @@ -514,7 +514,7 @@ namespace LC.Newtonsoft.Json /// /// Gets or sets the maximum depth allowed when reading JSON. Reading past this depth will throw a . /// A null value means there is no maximum. - /// The default value is 128. + /// The default value is null. /// public virtual int? MaxDepth { @@ -865,9 +865,12 @@ namespace LC.Newtonsoft.Json /// The type of the object to deserialize. /// The instance of being deserialized. [DebuggerStepThrough] - public T? Deserialize(JsonReader reader) + [return: MaybeNull] + public T Deserialize(JsonReader reader) { - return (T?)Deserialize(reader, typeof(T)); +#pragma warning disable CS8601 // Possible null reference assignment. + return (T)Deserialize(reader, typeof(T)); +#pragma warning restore CS8601 // Possible null reference assignment. } /// diff --git a/Libs/Newtonsoft.Json.AOT/JsonSerializerSettings.cs b/Libs/Newtonsoft.Json.AOT/JsonSerializerSettings.cs index e0d42b8..61aefc1 100644 --- a/Libs/Newtonsoft.Json.AOT/JsonSerializerSettings.cs +++ b/Libs/Newtonsoft.Json.AOT/JsonSerializerSettings.cs @@ -61,7 +61,6 @@ namespace LC.Newtonsoft.Json internal static readonly CultureInfo DefaultCulture; internal const bool DefaultCheckAdditionalContent = false; internal const string DefaultDateFormatString = @"yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK"; - internal const int DefaultMaxDepth = 64; internal Formatting? _formatting; internal DateFormatHandling? _dateFormatHandling; @@ -326,11 +325,11 @@ namespace LC.Newtonsoft.Json /// /// Gets or sets the maximum depth allowed when reading JSON. Reading past this depth will throw a . /// A null value means there is no maximum. - /// The default value is 128. + /// The default value is null. /// public int? MaxDepth { - get => _maxDepthSet ? _maxDepth : DefaultMaxDepth; + get => _maxDepth; set { if (value <= 0) diff --git a/Libs/Newtonsoft.Json.AOT/JsonWriter.cs b/Libs/Newtonsoft.Json.AOT/JsonWriter.cs index 3149fb4..92a88b7 100644 --- a/Libs/Newtonsoft.Json.AOT/JsonWriter.cs +++ b/Libs/Newtonsoft.Json.AOT/JsonWriter.cs @@ -62,7 +62,7 @@ namespace LC.Newtonsoft.Json // array that gives a new state based on the current state an the token being written private static readonly State[][] StateArray; - internal static readonly State[][] StateArrayTemplate = new[] + internal static readonly State[][] StateArrayTempate = new[] { // Start PropertyName ObjectStart Object ArrayStart Array ConstructorStart Constructor Closed Error // @@ -78,9 +78,9 @@ namespace LC.Newtonsoft.Json internal static State[][] BuildStateArray() { - List allStates = StateArrayTemplate.ToList(); - State[] errorStates = StateArrayTemplate[0]; - State[] valueStates = StateArrayTemplate[7]; + List allStates = StateArrayTempate.ToList(); + State[] errorStates = StateArrayTempate[0]; + State[] valueStates = StateArrayTempate[7]; EnumInfo enumValuesAndNames = EnumUtils.GetEnumValuesAndNames(typeof(JsonToken)); @@ -579,9 +579,8 @@ namespace LC.Newtonsoft.Json } break; case JsonToken.String: - // Allow for a null string. This matches JTokenReader behavior which can read - // a JsonToken.String with a null value. - WriteValue(value?.ToString()); + ValidationUtils.ArgumentNotNull(value, nameof(value)); + WriteValue(value.ToString()); break; case JsonToken.Boolean: ValidationUtils.ArgumentNotNull(value, nameof(value)); diff --git a/Libs/Newtonsoft.Json.AOT/LC.Newtonsoft.Json.AOT.csproj b/Libs/Newtonsoft.Json.AOT/LC.Newtonsoft.Json.AOT.csproj index 4703b3c..a0de028 100644 --- a/Libs/Newtonsoft.Json.AOT/LC.Newtonsoft.Json.AOT.csproj +++ b/Libs/Newtonsoft.Json.AOT/LC.Newtonsoft.Json.AOT.csproj @@ -1,9 +1,10 @@  + netstandard2.0 AOT - netstandard2.0 + netstandard2.0;net45;portable-net45+win8+wpa81+wp8 $(LibraryFrameworks) - 9.0 + 8.0 11.0.0.0 11.0.1 @@ -38,18 +39,17 @@ - - Newtonsoft.Json.xml - - + + + - + - net46 + net45 Json.NET for Unity tests (NOT FOR PRODUCTION) DEBUG;NET45;HAVE_ADO_NET;HAVE_APP_DOMAIN;HAVE_ASYNC;HAVE_BIG_INTEGER;HAVE_BINARY_EXCEPTION_SERIALIZATION;HAVE_BINARY_FORMATTER;HAVE_BINARY_SERIALIZATION;HAVE_CAS;HAVE_CHAR_TO_LOWER_WITH_CULTURE;HAVE_CHAR_TO_STRING_WITH_CULTURE;HAVE_COM_ATTRIBUTES;HAVE_COMPONENT_MODEL;HAVE_CONCURRENT_COLLECTIONS;HAVE_CONCURRENT_DICTIONARY;HAVE_COVARIANT_GENERICS;HAVE_DATA_CONTRACTS;HAVE_DATE_TIME_OFFSET;HAVE_DB_NULL_TYPE_CODE;HAVE_DYNAMIC;HAVE_EMPTY_TYPES;HAVE_ENTITY_FRAMEWORK;HAVE_EXPRESSIONS;HAVE_FAST_REVERSE;HAVE_FSHARP_TYPES;HAVE_FULL_REFLECTION;HAVE_GUID_TRY_PARSE;HAVE_HASH_SET;HAVE_ICLONEABLE;HAVE_ICONVERTIBLE;HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_INOTIFY_PROPERTY_CHANGING;HAVE_ISET;HAVE_LINQ;HAVE_MEMORY_BARRIER;HAVE_METHOD_IMPL_ATTRIBUTE;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_READ_ONLY_COLLECTIONS;HAVE_REFLECTION_EMIT;HAVE_SECURITY_SAFE_CRITICAL_ATTRIBUTE;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STREAM_READER_WRITER_CLOSE;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_TRACE_WRITER;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XLINQ;HAVE_XML_DOCUMENT;HAVE_XML_DOCUMENT_TYPE;$(AdditionalConstants) bin\$(Configuration)\unity-tests @@ -75,7 +75,19 @@ NETSTANDARD2_0;UNITY_LTS;HAVE_ADO_NET;HAVE_APP_DOMAIN;HAVE_ASYNC;HAVE_BIG_INTEGER;HAVE_BINARY_EXCEPTION_SERIALIZATION;HAVE_BINARY_FORMATTER;HAVE_BINARY_SERIALIZATION;HAVE_CHAR_TO_LOWER_WITH_CULTURE;HAVE_CHAR_TO_STRING_WITH_CULTURE;HAVE_COM_ATTRIBUTES;HAVE_COMPONENT_MODEL;HAVE_CONCURRENT_COLLECTIONS;HAVE_CONCURRENT_DICTIONARY;HAVE_COVARIANT_GENERICS;HAVE_DATA_CONTRACTS;HAVE_DATE_TIME_OFFSET;HAVE_DB_NULL_TYPE_CODE;HAVE_DYNAMIC;HAVE_EMPTY_TYPES;HAVE_ENTITY_FRAMEWORK;HAVE_EXPRESSIONS;HAVE_FAST_REVERSE;HAVE_FSHARP_TYPES;HAVE_FULL_REFLECTION;HAVE_GUID_TRY_PARSE;HAVE_HASH_SET;HAVE_ICLONEABLE;HAVE_ICONVERTIBLE;HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_INOTIFY_PROPERTY_CHANGING;HAVE_ISET;HAVE_LINQ;HAVE_MEMORY_BARRIER;HAVE_METHOD_IMPL_ATTRIBUTE;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_READ_ONLY_COLLECTIONS;HAVE_SECURITY_SAFE_CRITICAL_ATTRIBUTE;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STREAM_READER_WRITER_CLOSE;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_TRACE_WRITER;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XLINQ;HAVE_XML_DOCUMENT;HAVE_XML_DOCUMENT_TYPE;$(AdditionalConstants) bin\$(Configuration)\unity-aot + + + portable-net45+win8+wpa81+wp8 + Json.NET for Unity portable (wp8) + PORTABLE;HAVE_ASYNC;HAVE_COVARIANT_GENERICS;HAVE_DATA_CONTRACTS;HAVE_DATE_TIME_OFFSET;HAVE_DYNAMIC;HAVE_EXPRESSIONS;HAVE_FAST_REVERSE;HAVE_FSHARP_TYPES;HAVE_GUID_TRY_PARSE;HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_ISET;HAVE_LINQ;HAVE_METHOD_IMPL_ATTRIBUTE;HAVE_OBSOLETE_FORMATTER_ASSEMBLY_STYLE;HAVE_READ_ONLY_COLLECTIONS;HAVE_REFLECTION_BINDER;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XLINQ;$(AdditionalConstants) + .NETPortable + v4.5 + Profile259 + .NETPortable,Version=v0.0,Profile=Profile259 + $(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets + bin\$(Configuration)\unity-portable-net45 + - NETSTANDARD2_0;UNITY_LTS;HAVE_ADO_NET;HAVE_APP_DOMAIN;HAVE_ASYNC;HAVE_BIG_INTEGER;HAVE_BINARY_EXCEPTION_SERIALIZATION;HAVE_BINARY_FORMATTER;HAVE_BINARY_SERIALIZATION;HAVE_CHAR_TO_LOWER_WITH_CULTURE;HAVE_CHAR_TO_STRING_WITH_CULTURE;HAVE_COM_ATTRIBUTES;HAVE_COMPONENT_MODEL;HAVE_CONCURRENT_COLLECTIONS;HAVE_CONCURRENT_DICTIONARY;HAVE_COVARIANT_GENERICS;HAVE_DATA_CONTRACTS;HAVE_DATE_TIME_OFFSET;HAVE_DB_NULL_TYPE_CODE;HAVE_DYNAMIC;HAVE_EMPTY_TYPES;HAVE_ENTITY_FRAMEWORK;HAVE_EXPRESSIONS;HAVE_FAST_REVERSE;HAVE_FSHARP_TYPES;HAVE_FULL_REFLECTION;HAVE_GUID_TRY_PARSE;HAVE_HASH_SET;HAVE_ICLONEABLE;HAVE_ICONVERTIBLE;HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_INOTIFY_PROPERTY_CHANGING;HAVE_ISET;HAVE_LINQ;HAVE_MEMORY_BARRIER;HAVE_METHOD_IMPL_ATTRIBUTE;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_READ_ONLY_COLLECTIONS;HAVE_SECURITY_SAFE_CRITICAL_ATTRIBUTE;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STREAM_READER_WRITER_CLOSE;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_TRACE_WRITER;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XLINQ;HAVE_XML_DOCUMENT;HAVE_XML_DOCUMENT_TYPE;$(AdditionalConstants) + HAVE_ADO_NET;HAVE_APP_DOMAIN;HAVE_ASYNC;HAVE_BIG_INTEGER;HAVE_BINARY_EXCEPTION_SERIALIZATION;HAVE_BINARY_FORMATTER;HAVE_BINARY_SERIALIZATION;HAVE_CHAR_TO_LOWER_WITH_CULTURE;HAVE_CHAR_TO_STRING_WITH_CULTURE;HAVE_COM_ATTRIBUTES;HAVE_COMPONENT_MODEL;HAVE_CONCURRENT_COLLECTIONS;HAVE_CONCURRENT_DICTIONARY;HAVE_COVARIANT_GENERICS;HAVE_DATA_CONTRACTS;HAVE_DATE_TIME_OFFSET;HAVE_DB_NULL_TYPE_CODE;HAVE_DYNAMIC;HAVE_EMPTY_TYPES;HAVE_ENTITY_FRAMEWORK;HAVE_EXPRESSIONS;HAVE_FAST_REVERSE;HAVE_FSHARP_TYPES;HAVE_FULL_REFLECTION;HAVE_GUID_TRY_PARSE;HAVE_HASH_SET;HAVE_ICLONEABLE;HAVE_ICONVERTIBLE;HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_INOTIFY_PROPERTY_CHANGING;HAVE_ISET;HAVE_LINQ;HAVE_MEMORY_BARRIER;HAVE_METHOD_IMPL_ATTRIBUTE;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_READ_ONLY_COLLECTIONS;HAVE_SECURITY_SAFE_CRITICAL_ATTRIBUTE;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STREAM_READER_WRITER_CLOSE;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_TRACE_WRITER;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XLINQ;HAVE_XML_DOCUMENT;HAVE_XML_DOCUMENT_TYPE;;DEBUG;NETSTANDARD;NETSTANDARD2_0; diff --git a/Libs/Newtonsoft.Json.AOT/Linq/Extensions.cs b/Libs/Newtonsoft.Json.AOT/Linq/Extensions.cs index e401a5c..0e61485 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/Extensions.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/Extensions.cs @@ -115,7 +115,7 @@ namespace LC.Newtonsoft.Json.Linq /// 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(); + return Values(source, key).AsJEnumerable(); } /// @@ -135,7 +135,7 @@ namespace LC.Newtonsoft.Json.Linq /// 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) + public static IEnumerable Values(this IEnumerable source, object key) { return Values(source, key); } @@ -146,7 +146,7 @@ namespace LC.Newtonsoft.Json.Linq /// 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) + public static IEnumerable Values(this IEnumerable source) { return Values(source, null); } @@ -157,7 +157,7 @@ namespace LC.Newtonsoft.Json.Linq /// The type to convert the value to. /// A cast as a of . /// A converted value. - public static U? Value(this IEnumerable value) + public static U Value(this IEnumerable value) { return value.Value(); } @@ -169,7 +169,7 @@ namespace LC.Newtonsoft.Json.Linq /// The type to convert the value to. /// A cast as a of . /// A converted value. - public static U? Value(this IEnumerable value) where T : JToken + public static U Value(this IEnumerable value) where T : JToken { ValidationUtils.ArgumentNotNull(value, nameof(value)); @@ -181,7 +181,7 @@ namespace LC.Newtonsoft.Json.Linq return token.Convert(); } - internal static IEnumerable Values(this IEnumerable source, object? key) where T : JToken + internal static IEnumerable Values(this IEnumerable source, object? key) where T : JToken { ValidationUtils.ArgumentNotNull(source, nameof(source)); @@ -226,7 +226,7 @@ namespace LC.Newtonsoft.Json.Linq /// 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(); + return Children(source).AsJEnumerable(); } /// @@ -236,14 +236,14 @@ namespace LC.Newtonsoft.Json.Linq /// The type to convert the values to. /// The source collection type. /// An that contains the converted values of every token in the source collection. - public static IEnumerable Children(this IEnumerable source) where T : JToken + public static IEnumerable Children(this IEnumerable source) where T : JToken { ValidationUtils.ArgumentNotNull(source, nameof(source)); return source.SelectMany(c => c.Children()).Convert(); } - internal static IEnumerable Convert(this IEnumerable source) where T : JToken + internal static IEnumerable Convert(this IEnumerable source) where T : JToken { ValidationUtils.ArgumentNotNull(source, nameof(source)); @@ -253,7 +253,8 @@ namespace LC.Newtonsoft.Json.Linq } } - internal static U? Convert(this T token) where T : JToken? + [return: MaybeNull] + internal static U Convert(this T token) where T : JToken? { if (token == null) { diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JContainer.cs b/Libs/Newtonsoft.Json.AOT/Linq/JContainer.cs index 8b17d56..8ce454d 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JContainer.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JContainer.cs @@ -114,11 +114,9 @@ namespace LC.Newtonsoft.Json.Linq int i = 0; foreach (JToken child in other) { - TryAddInternal(i, child, false); + AddInternal(i, child, false); i++; } - - CopyAnnotations(this, other); } internal void CheckReentrancy() @@ -275,7 +273,7 @@ namespace LC.Newtonsoft.Json.Linq /// /// A containing the child values of this , in document order. /// - public override IEnumerable Values() where T : default + public override IEnumerable Values() { return ChildrenTokens.Convert(); } @@ -318,7 +316,7 @@ namespace LC.Newtonsoft.Json.Linq } } - internal bool IsMultiContent([NotNullWhen(true)]object? content) + internal bool IsMultiContent([NotNull]object? content) { return (content is IEnumerable && !(content is string) && !(content is JToken) && !(content is byte[])); } @@ -349,7 +347,7 @@ namespace LC.Newtonsoft.Json.Linq internal abstract int IndexOfItem(JToken? item); - internal virtual bool InsertItem(int index, JToken? item, bool skipParentCheck) + internal virtual void InsertItem(int index, JToken? item, bool skipParentCheck) { IList children = ChildrenTokens; @@ -396,8 +394,6 @@ namespace LC.Newtonsoft.Json.Linq OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index)); } #endif - - return true; } internal virtual void RemoveItemAt(int index) @@ -635,17 +631,12 @@ namespace LC.Newtonsoft.Json.Linq /// The content to be added. public virtual void Add(object? content) { - TryAddInternal(ChildrenTokens.Count, content, false); - } - - internal bool TryAdd(object? content) - { - return TryAddInternal(ChildrenTokens.Count, content, false); + AddInternal(ChildrenTokens.Count, content, false); } internal void AddAndSkipParentCheck(JToken token) { - TryAddInternal(ChildrenTokens.Count, token, true); + AddInternal(ChildrenTokens.Count, token, true); } /// @@ -654,10 +645,10 @@ namespace LC.Newtonsoft.Json.Linq /// The content to be added. public void AddFirst(object? content) { - TryAddInternal(0, content, false); + AddInternal(0, content, false); } - internal bool TryAddInternal(int index, object? content, bool skipParentCheck) + internal void AddInternal(int index, object? content, bool skipParentCheck) { if (IsMultiContent(content)) { @@ -666,17 +657,15 @@ namespace LC.Newtonsoft.Json.Linq int multiIndex = index; foreach (object c in enumerable) { - TryAddInternal(multiIndex, c, skipParentCheck); + AddInternal(multiIndex, c, skipParentCheck); multiIndex++; } - - return true; } else { JToken item = CreateFromContent(content); - return InsertItem(index, item, skipParentCheck); + InsertItem(index, item, skipParentCheck); } } diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JEnumerable.cs b/Libs/Newtonsoft.Json.AOT/Linq/JEnumerable.cs index 9bd3a49..8d4665e 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JEnumerable.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JEnumerable.cs @@ -88,7 +88,7 @@ namespace LC.Newtonsoft.Json.Linq return JEnumerable.Empty; } - return new JEnumerable(_enumerable.Values(key)!); + return new JEnumerable(_enumerable.Values(key)); } } diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JObject.cs b/Libs/Newtonsoft.Json.AOT/Linq/JObject.cs index 0e63fcf..4bce2fd 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JObject.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JObject.cs @@ -135,15 +135,15 @@ namespace LC.Newtonsoft.Json.Linq return _properties.IndexOfReference(item); } - internal override bool InsertItem(int index, JToken? item, bool skipParentCheck) + internal override void InsertItem(int index, JToken? item, bool skipParentCheck) { // don't add comments to JObject, no name to reference comment by if (item != null && item.Type == JTokenType.Comment) { - return false; + return; } - return base.InsertItem(index, item, skipParentCheck); + base.InsertItem(index, item, skipParentCheck); } internal override void ValidateToken(JToken o, JToken? existing) diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JProperty.cs b/Libs/Newtonsoft.Json.AOT/Linq/JProperty.cs index 5745e2c..16a86c0 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JProperty.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JProperty.cs @@ -241,12 +241,12 @@ namespace LC.Newtonsoft.Json.Linq return _content.IndexOf(item); } - internal override bool InsertItem(int index, JToken? item, bool skipParentCheck) + internal override void InsertItem(int index, JToken? item, bool skipParentCheck) { // don't add comments to JProperty if (item != null && item.Type == JTokenType.Comment) { - return false; + return; } if (Value != null) @@ -254,7 +254,7 @@ namespace LC.Newtonsoft.Json.Linq throw new JsonException("{0} cannot have multiple values.".FormatWith(CultureInfo.InvariantCulture, typeof(JProperty))); } - return base.InsertItem(0, item, false); + base.InsertItem(0, item, false); } internal override bool ContainsItem(JToken? item) diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JToken.cs b/Libs/Newtonsoft.Json.AOT/Linq/JToken.cs index bb480af..2ebdeaa 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JToken.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JToken.cs @@ -240,7 +240,7 @@ namespace LC.Newtonsoft.Json.Linq } int index = _parent.IndexOfItem(this); - _parent.TryAddInternal(index + 1, content, false); + _parent.AddInternal(index + 1, content, false); } /// @@ -255,7 +255,7 @@ namespace LC.Newtonsoft.Json.Linq } int index = _parent.IndexOfItem(this); - _parent.TryAddInternal(index, content, false); + _parent.AddInternal(index, content, false); } /// @@ -334,7 +334,7 @@ namespace LC.Newtonsoft.Json.Linq /// The type to convert the token to. /// The token key. /// The converted token value. - public virtual T? Value(object key) + public virtual T Value(object key) { JToken? token = this[key]; @@ -378,7 +378,7 @@ namespace LC.Newtonsoft.Json.Linq /// /// The type to convert the values to. /// A containing the child values of this , in document order. - public virtual IEnumerable Values() + public virtual IEnumerable Values() { throw new InvalidOperationException("Cannot access child value on {0}.".FormatWith(CultureInfo.InvariantCulture, GetType())); } @@ -485,7 +485,7 @@ namespace LC.Newtonsoft.Json.Linq return (Array.IndexOf(validTypes, o.Type) != -1) || (nullable && (o.Type == JTokenType.Null || o.Type == JTokenType.Undefined)); } - #region Cast from operators +#region Cast from operators /// /// Performs an explicit conversion from to . /// @@ -1497,9 +1497,9 @@ namespace LC.Newtonsoft.Json.Linq return ConvertUtils.ToBigInteger(v.Value); } #endif - #endregion +#endregion - #region Cast to operators +#region Cast to operators /// /// Performs an implicit conversion from to . /// @@ -1863,7 +1863,7 @@ namespace LC.Newtonsoft.Json.Linq { return new JValue(value); } - #endregion +#endregion IEnumerator IEnumerable.GetEnumerator() { @@ -1929,9 +1929,12 @@ namespace LC.Newtonsoft.Json.Linq /// /// The object type that the token will be deserialized to. /// The new object created from the JSON value. - public T? ToObject() + [return: MaybeNull] + public T ToObject() { - return (T?)ToObject(typeof(T)); +#pragma warning disable CS8601 // Possible null reference assignment. + return (T)ToObject(typeof(T)); +#pragma warning restore CS8601 // Possible null reference assignment. } /// @@ -2062,9 +2065,12 @@ namespace LC.Newtonsoft.Json.Linq /// The object type that the token will be deserialized to. /// The that will be used when creating the object. /// The new object created from the JSON value. - public T? ToObject(JsonSerializer jsonSerializer) + [return: MaybeNull] + public T ToObject(JsonSerializer jsonSerializer) { - return (T?)ToObject(typeof(T), jsonSerializer); +#pragma warning disable CS8601 // Possible null reference assignment. + return (T)ToObject(typeof(T), jsonSerializer); +#pragma warning restore CS8601 // Possible null reference assignment. } /// @@ -2307,7 +2313,7 @@ namespace LC.Newtonsoft.Json.Linq /// A , or null. public JToken? SelectToken(string path) { - return SelectToken(path, settings: null); + return SelectToken(path, false); } /// @@ -2319,28 +2325,11 @@ namespace LC.Newtonsoft.Json.Linq /// A flag to indicate whether an error should be thrown if no tokens are found when evaluating part of the expression. /// A . public JToken? SelectToken(string path, bool errorWhenNoMatch) - { - JsonSelectSettings? settings = errorWhenNoMatch - ? new JsonSelectSettings { ErrorWhenNoMatch = true } - : null; - - return SelectToken(path, settings); - } - - /// - /// Selects a using a JSONPath expression. Selects the token that matches the object path. - /// - /// - /// A that contains a JSONPath expression. - /// - /// The used to select tokens. - /// A . - public JToken? SelectToken(string path, JsonSelectSettings? settings) { JPath p = new JPath(path); JToken? token = null; - foreach (JToken t in p.Evaluate(this, this, settings)) + foreach (JToken t in p.Evaluate(this, this, errorWhenNoMatch)) { if (token != null) { @@ -2362,7 +2351,7 @@ namespace LC.Newtonsoft.Json.Linq /// An of that contains the selected elements. public IEnumerable SelectTokens(string path) { - return SelectTokens(path, settings: null); + return SelectTokens(path, false); } /// @@ -2375,25 +2364,8 @@ namespace LC.Newtonsoft.Json.Linq /// An of that contains the selected elements. public IEnumerable SelectTokens(string path, bool errorWhenNoMatch) { - JsonSelectSettings? settings = errorWhenNoMatch - ? new JsonSelectSettings { ErrorWhenNoMatch = true } - : null; - - return SelectTokens(path, settings); - } - - /// - /// Selects a collection of elements using a JSONPath expression. - /// - /// - /// A that contains a JSONPath expression. - /// - /// The used to select tokens. - /// An of that contains the selected elements. - public IEnumerable SelectTokens(string path, JsonSelectSettings? settings) - { - var p = new JPath(path); - return p.Evaluate(this, this, settings); + JPath p = new JPath(path); + return p.Evaluate(this, this, errorWhenNoMatch); } #if HAVE_DYNAMIC @@ -2734,17 +2706,5 @@ namespace LC.Newtonsoft.Json.Linq } } } - - internal void CopyAnnotations(JToken target, JToken source) - { - if (source._annotations is object[] annotations) - { - target._annotations = annotations.ToArray(); - } - else - { - target._annotations = source._annotations; - } - } } } \ No newline at end of file diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JTokenWriter.cs b/Libs/Newtonsoft.Json.AOT/Linq/JTokenWriter.cs index ce3efde..f6a0684 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JTokenWriter.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JTokenWriter.cs @@ -196,17 +196,12 @@ namespace LC.Newtonsoft.Json.Linq { if (_parent != null) { - // TryAdd will return false if an invalid JToken type is added. - // For example, a JComment can't be added to a JObject. - // If there is an invalid JToken type then skip it. - if (_parent.TryAdd(value)) - { - _current = _parent.Last; + _parent.Add(value); + _current = _parent.Last; - if (_parent.Type == JTokenType.Property) - { - _parent = _parent.Parent; - } + if (_parent.Type == JTokenType.Property) + { + _parent = _parent.Parent; } } else diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JValue.cs b/Libs/Newtonsoft.Json.AOT/Linq/JValue.cs index 12a59c0..58280ef 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JValue.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JValue.cs @@ -64,7 +64,6 @@ namespace LC.Newtonsoft.Json.Linq public JValue(JValue other) : this(other.Value, other.Type) { - CopyAnnotations(this, other); } /// @@ -842,7 +841,7 @@ namespace LC.Newtonsoft.Json.Linq /// true if the current object is equal to the parameter; otherwise, false. /// /// An object to compare with this object. - public bool Equals(JValue? other) + public bool Equals([AllowNull] JValue other) { if (other == null) { diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ArrayIndexFilter.cs b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ArrayIndexFilter.cs index dd0654c..e8f8fbc 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ArrayIndexFilter.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ArrayIndexFilter.cs @@ -8,13 +8,13 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath { public int? Index { get; set; } - public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) + public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, bool errorWhenNoMatch) { foreach (JToken t in current) { if (Index != null) { - JToken? v = GetTokenIndex(t, settings, Index.GetValueOrDefault()); + JToken? v = GetTokenIndex(t, errorWhenNoMatch, Index.GetValueOrDefault()); if (v != null) { @@ -32,7 +32,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath } else { - if (settings?.ErrorWhenNoMatch ?? false) + if (errorWhenNoMatch) { throw new JsonException("Index * not valid on {0}.".FormatWith(CultureInfo.InvariantCulture, t.GetType().Name)); } diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ArrayMultipleIndexFilter.cs b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ArrayMultipleIndexFilter.cs index fb7c2e4..21dd528 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ArrayMultipleIndexFilter.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ArrayMultipleIndexFilter.cs @@ -11,13 +11,13 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath Indexes = indexes; } - public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) + public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, bool errorWhenNoMatch) { foreach (JToken t in current) { foreach (int i in Indexes) { - JToken? v = GetTokenIndex(t, settings, i); + JToken? v = GetTokenIndex(t, errorWhenNoMatch, i); if (v != null) { diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ArraySliceFilter.cs b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ArraySliceFilter.cs index 2370da8..cf9d964 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ArraySliceFilter.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ArraySliceFilter.cs @@ -11,7 +11,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath public int? End { get; set; } public int? Step { get; set; } - public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) + public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, bool errorWhenNoMatch) { if (Step == 0) { @@ -56,7 +56,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath } else { - if (settings?.ErrorWhenNoMatch ?? false) + if (errorWhenNoMatch) { throw new JsonException("Array slice of {0} to {1} returned no results.".FormatWith(CultureInfo.InvariantCulture, Start != null ? Start.GetValueOrDefault().ToString(CultureInfo.InvariantCulture) : "*", @@ -66,7 +66,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath } else { - if (settings?.ErrorWhenNoMatch ?? false) + if (errorWhenNoMatch) { throw new JsonException("Array slice is not valid on {0}.".FormatWith(CultureInfo.InvariantCulture, t.GetType().Name)); } diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/FieldFilter.cs b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/FieldFilter.cs index d1ded0c..e1bd8be 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/FieldFilter.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/FieldFilter.cs @@ -13,7 +13,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath Name = name; } - public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) + public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, bool errorWhenNoMatch) { foreach (JToken t in current) { @@ -27,7 +27,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath { yield return v; } - else if (settings?.ErrorWhenNoMatch ?? false) + else if (errorWhenNoMatch) { throw new JsonException("Property '{0}' does not exist on JObject.".FormatWith(CultureInfo.InvariantCulture, Name)); } @@ -42,7 +42,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath } else { - if (settings?.ErrorWhenNoMatch ?? false) + if (errorWhenNoMatch) { throw new JsonException("Property '{0}' not valid on {1}.".FormatWith(CultureInfo.InvariantCulture, Name ?? "*", t.GetType().Name)); } diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/FieldMultipleFilter.cs b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/FieldMultipleFilter.cs index 196290a..8c7a198 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/FieldMultipleFilter.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/FieldMultipleFilter.cs @@ -18,7 +18,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath Names = names; } - public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) + public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, bool errorWhenNoMatch) { foreach (JToken t in current) { @@ -33,7 +33,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath yield return v; } - if (settings?.ErrorWhenNoMatch ?? false) + if (errorWhenNoMatch) { throw new JsonException("Property '{0}' does not exist on JObject.".FormatWith(CultureInfo.InvariantCulture, name)); } @@ -41,7 +41,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath } else { - if (settings?.ErrorWhenNoMatch ?? false) + if (errorWhenNoMatch) { throw new JsonException("Properties {0} not valid on {1}.".FormatWith(CultureInfo.InvariantCulture, string.Join(", ", Names.Select(n => "'" + n + "'") #if !HAVE_STRING_JOIN_WITH_ENUMERABLE diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/JPath.cs b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/JPath.cs index d4d0ad7..ba177d5 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/JPath.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/JPath.cs @@ -874,17 +874,17 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath } } - internal IEnumerable Evaluate(JToken root, JToken t, JsonSelectSettings? settings) + internal IEnumerable Evaluate(JToken root, JToken t, bool errorWhenNoMatch) { - return Evaluate(Filters, root, t, settings); + return Evaluate(Filters, root, t, errorWhenNoMatch); } - internal static IEnumerable Evaluate(List filters, JToken root, JToken t, JsonSelectSettings? settings) + internal static IEnumerable Evaluate(List filters, JToken root, JToken t, bool errorWhenNoMatch) { IEnumerable current = new[] { t }; foreach (PathFilter filter in filters) { - current = filter.ExecuteFilter(root, current, settings); + current = filter.ExecuteFilter(root, current, errorWhenNoMatch); } return current; diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/PathFilter.cs b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/PathFilter.cs index d859b96..46d8aad 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/PathFilter.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/PathFilter.cs @@ -6,15 +6,15 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath { internal abstract class PathFilter { - public abstract IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings); + public abstract IEnumerable ExecuteFilter(JToken root, IEnumerable current, bool errorWhenNoMatch); - protected static JToken? GetTokenIndex(JToken t, JsonSelectSettings? settings, int index) + protected static JToken? GetTokenIndex(JToken t, bool errorWhenNoMatch, int index) { if (t is JArray a) { if (a.Count <= index) { - if (settings?.ErrorWhenNoMatch ?? false) + if (errorWhenNoMatch) { throw new JsonException("Index {0} outside the bounds of JArray.".FormatWith(CultureInfo.InvariantCulture, index)); } @@ -28,7 +28,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath { if (c.Count <= index) { - if (settings?.ErrorWhenNoMatch ?? false) + if (errorWhenNoMatch) { throw new JsonException("Index {0} outside the bounds of JConstructor.".FormatWith(CultureInfo.InvariantCulture, index)); } @@ -40,7 +40,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath } else { - if (settings?.ErrorWhenNoMatch ?? false) + if (errorWhenNoMatch) { throw new JsonException("Index {0} not valid on {1}.".FormatWith(CultureInfo.InvariantCulture, index, t.GetType().Name)); } diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/QueryExpression.cs b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/QueryExpression.cs index 26756d4..0dc4333 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/QueryExpression.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/QueryExpression.cs @@ -39,13 +39,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath Operator = @operator; } - // For unit tests - public bool IsMatch(JToken root, JToken t) - { - return IsMatch(root, t, null); - } - - public abstract bool IsMatch(JToken root, JToken t, JsonSelectSettings? settings); + public abstract bool IsMatch(JToken root, JToken t); } internal class CompositeExpression : QueryExpression @@ -57,14 +51,14 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath Expressions = new List(); } - public override bool IsMatch(JToken root, JToken t, JsonSelectSettings? settings) + public override bool IsMatch(JToken root, JToken t) { switch (Operator) { case QueryOperator.And: foreach (QueryExpression e in Expressions) { - if (!e.IsMatch(root, t, settings)) + if (!e.IsMatch(root, t)) { return false; } @@ -73,7 +67,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath case QueryOperator.Or: foreach (QueryExpression e in Expressions) { - if (e.IsMatch(root, t, settings)) + if (e.IsMatch(root, t)) { return true; } @@ -105,13 +99,13 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath if (o is List pathFilters) { - return JPath.Evaluate(pathFilters, root, t, null); + return JPath.Evaluate(pathFilters, root, t, false); } return CollectionUtils.ArrayEmpty(); } - public override bool IsMatch(JToken root, JToken t, JsonSelectSettings? settings) + public override bool IsMatch(JToken root, JToken t) { if (Operator == QueryOperator.Exists) { @@ -130,7 +124,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath JToken leftResult = leftResults.Current; foreach (JToken rightResult in rightResults) { - if (MatchTokens(leftResult, rightResult, settings)) + if (MatchTokens(leftResult, rightResult)) { return true; } @@ -142,14 +136,14 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath return false; } - private bool MatchTokens(JToken leftResult, JToken rightResult, JsonSelectSettings? settings) + private bool MatchTokens(JToken leftResult, JToken rightResult) { if (leftResult is JValue leftValue && rightResult is JValue rightValue) { switch (Operator) { case QueryOperator.RegexEquals: - if (RegexEquals(leftValue, rightValue, settings)) + if (RegexEquals(leftValue, rightValue)) { return true; } @@ -221,7 +215,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath return false; } - private static bool RegexEquals(JValue input, JValue pattern, JsonSelectSettings? settings) + private static bool RegexEquals(JValue input, JValue pattern) { if (input.Type != JTokenType.String || pattern.Type != JTokenType.String) { @@ -234,12 +228,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath string patternText = regexText.Substring(1, patternOptionDelimiterIndex - 1); string optionsText = regexText.Substring(patternOptionDelimiterIndex + 1); -#if HAVE_REGEX_TIMEOUTS - TimeSpan timeout = settings?.RegexMatchTimeout ?? Regex.InfiniteMatchTimeout; - return Regex.IsMatch((string)input.Value!, patternText, MiscellaneousUtils.GetRegexOptions(optionsText), timeout); -#else return Regex.IsMatch((string)input.Value!, patternText, MiscellaneousUtils.GetRegexOptions(optionsText)); -#endif } internal static bool EqualsWithStringCoercion(JValue value, JValue queryValue) diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/QueryFilter.cs b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/QueryFilter.cs index 54f540f..2407886 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/QueryFilter.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/QueryFilter.cs @@ -12,13 +12,13 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath Expression = expression; } - public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) + public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, bool errorWhenNoMatch) { foreach (JToken t in current) { foreach (JToken v in t) { - if (Expression.IsMatch(root, v, settings)) + if (Expression.IsMatch(root, v)) { yield return v; } diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/QueryScanFilter.cs b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/QueryScanFilter.cs index ef71ab5..902244d 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/QueryScanFilter.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/QueryScanFilter.cs @@ -12,7 +12,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath Expression = expression; } - public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) + public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, bool errorWhenNoMatch) { foreach (JToken t in current) { @@ -20,7 +20,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath { foreach (JToken d in c.DescendantsAndSelf()) { - if (Expression.IsMatch(root, d, settings)) + if (Expression.IsMatch(root, d)) { yield return d; } @@ -28,7 +28,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath } else { - if (Expression.IsMatch(root, t, settings)) + if (Expression.IsMatch(root, t)) { yield return t; } diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/RootFilter.cs b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/RootFilter.cs index 0c980c5..4a6b4a7 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/RootFilter.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/RootFilter.cs @@ -10,7 +10,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath { } - public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) + public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, bool errorWhenNoMatch) { return new[] { root }; } diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ScanFilter.cs b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ScanFilter.cs index 12c2306..7a3a44e 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ScanFilter.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ScanFilter.cs @@ -11,7 +11,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath Name = name; } - public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) + public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, bool errorWhenNoMatch) { foreach (JToken c in current) { diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ScanMultipleFilter.cs b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ScanMultipleFilter.cs index c805a4b..95e20ae 100644 --- a/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ScanMultipleFilter.cs +++ b/Libs/Newtonsoft.Json.AOT/Linq/JsonPath/ScanMultipleFilter.cs @@ -11,7 +11,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath _names = names; } - public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, JsonSelectSettings? settings) + public override IEnumerable ExecuteFilter(JToken root, IEnumerable current, bool errorWhenNoMatch) { foreach (JToken c in current) { diff --git a/Libs/Newtonsoft.Json.AOT/Linq/JsonSelectSettings.cs b/Libs/Newtonsoft.Json.AOT/Linq/JsonSelectSettings.cs deleted file mode 100644 index a5fa4f2..0000000 --- a/Libs/Newtonsoft.Json.AOT/Linq/JsonSelectSettings.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; - -namespace LC.Newtonsoft.Json.Linq -{ - /// - /// Specifies the settings used when selecting JSON. - /// - public class JsonSelectSettings - { -#if HAVE_REGEX_TIMEOUTS - /// - /// Gets or sets a timeout that will be used when executing regular expressions. - /// - /// The timeout that will be used when executing regular expressions. - public TimeSpan? RegexMatchTimeout { get; set; } -#endif - - /// - /// Gets or sets a flag that indicates whether an error should be thrown if - /// no tokens are found when evaluating part of the expression. - /// - /// - /// A flag that indicates whether an error should be thrown if - /// no tokens are found when evaluating part of the expression. - /// - public bool ErrorWhenNoMatch { get; set; } - } -} diff --git a/Libs/Newtonsoft.Json.AOT/Resources/link.xml b/Libs/Newtonsoft.Json.AOT/Resources/link.xml deleted file mode 100644 index 81488df..0000000 --- a/Libs/Newtonsoft.Json.AOT/Resources/link.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/Libs/Newtonsoft.Json.AOT/Serialization/JsonDictionaryContract.cs b/Libs/Newtonsoft.Json.AOT/Serialization/JsonDictionaryContract.cs index c28f415..651c701 100644 --- a/Libs/Newtonsoft.Json.AOT/Serialization/JsonDictionaryContract.cs +++ b/Libs/Newtonsoft.Json.AOT/Serialization/JsonDictionaryContract.cs @@ -118,21 +118,21 @@ namespace LC.Newtonsoft.Json.Serialization Type? keyType; Type? valueType; - if (ReflectionUtils.ImplementsGenericDefinition(NonNullableUnderlyingType, typeof(IDictionary<,>), out _genericCollectionDefinitionType)) + if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(IDictionary<,>), out _genericCollectionDefinitionType)) { keyType = _genericCollectionDefinitionType.GetGenericArguments()[0]; valueType = _genericCollectionDefinitionType.GetGenericArguments()[1]; - if (ReflectionUtils.IsGenericDefinition(NonNullableUnderlyingType, typeof(IDictionary<,>))) + if (ReflectionUtils.IsGenericDefinition(UnderlyingType, typeof(IDictionary<,>))) { CreatedType = typeof(Dictionary<,>).MakeGenericType(keyType, valueType); } - else if (NonNullableUnderlyingType.IsGenericType()) + else if (underlyingType.IsGenericType()) { // ConcurrentDictionary<,> + IDictionary setter + null value = error // wrap to use generic setter // https://github.com/JamesNK/Newtonsoft.Json/issues/1582 - Type typeDefinition = NonNullableUnderlyingType.GetGenericTypeDefinition(); + Type typeDefinition = underlyingType.GetGenericTypeDefinition(); if (typeDefinition.FullName == JsonTypeReflector.ConcurrentDictionaryTypeName) { ShouldCreateWrapper = true; @@ -140,17 +140,17 @@ namespace LC.Newtonsoft.Json.Serialization } #if HAVE_READ_ONLY_COLLECTIONS - IsReadOnlyOrFixedSize = ReflectionUtils.InheritsGenericDefinition(NonNullableUnderlyingType, typeof(ReadOnlyDictionary<,>)); + IsReadOnlyOrFixedSize = ReflectionUtils.InheritsGenericDefinition(underlyingType, typeof(ReadOnlyDictionary<,>)); #endif } #if HAVE_READ_ONLY_COLLECTIONS - else if (ReflectionUtils.ImplementsGenericDefinition(NonNullableUnderlyingType, typeof(IReadOnlyDictionary<,>), out _genericCollectionDefinitionType)) + else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(IReadOnlyDictionary<,>), out _genericCollectionDefinitionType)) { keyType = _genericCollectionDefinitionType.GetGenericArguments()[0]; valueType = _genericCollectionDefinitionType.GetGenericArguments()[1]; - if (ReflectionUtils.IsGenericDefinition(NonNullableUnderlyingType, typeof(IReadOnlyDictionary<,>))) + if (ReflectionUtils.IsGenericDefinition(UnderlyingType, typeof(IReadOnlyDictionary<,>))) { CreatedType = typeof(ReadOnlyDictionary<,>).MakeGenericType(keyType, valueType); } @@ -160,9 +160,9 @@ namespace LC.Newtonsoft.Json.Serialization #endif else { - ReflectionUtils.GetDictionaryKeyValueTypes(NonNullableUnderlyingType, out keyType, out valueType); + ReflectionUtils.GetDictionaryKeyValueTypes(UnderlyingType, out keyType, out valueType); - if (NonNullableUnderlyingType == typeof(IDictionary)) + if (UnderlyingType == typeof(IDictionary)) { CreatedType = typeof(Dictionary); } @@ -176,9 +176,9 @@ namespace LC.Newtonsoft.Json.Serialization typeof(IDictionary<,>).MakeGenericType(keyType, valueType)); #if HAVE_FSHARP_TYPES - if (!HasParameterizedCreatorInternal && NonNullableUnderlyingType.Name == FSharpUtils.FSharpMapTypeName) + if (!HasParameterizedCreatorInternal && underlyingType.Name == FSharpUtils.FSharpMapTypeName) { - FSharpUtils.EnsureInitialized(NonNullableUnderlyingType.Assembly()); + FSharpUtils.EnsureInitialized(underlyingType.Assembly()); _parameterizedCreator = FSharpUtils.Instance.CreateMap(keyType, valueType); } #endif @@ -207,7 +207,7 @@ namespace LC.Newtonsoft.Json.Serialization if (DictionaryKeyType != null && DictionaryValueType != null && ImmutableCollectionsUtils.TryBuildImmutableForDictionaryContract( - NonNullableUnderlyingType, + underlyingType, DictionaryKeyType, DictionaryValueType, out Type? immutableCreatedType, diff --git a/Libs/Newtonsoft.Json.AOT/Serialization/JsonSerializerInternalReader.cs b/Libs/Newtonsoft.Json.AOT/Serialization/JsonSerializerInternalReader.cs index 7f51152..9179b81 100644 --- a/Libs/Newtonsoft.Json.AOT/Serialization/JsonSerializerInternalReader.cs +++ b/Libs/Newtonsoft.Json.AOT/Serialization/JsonSerializerInternalReader.cs @@ -238,15 +238,6 @@ namespace LC.Newtonsoft.Json.Serialization token = writer.Token; } - if (contract != null && token != null) - { - if (!contract.UnderlyingType.IsAssignableFrom(token.GetType())) - { - throw JsonSerializationException.Create(reader, "Deserialized JSON type '{0}' is not compatible with expected type '{1}'." - .FormatWith(CultureInfo.InvariantCulture, token.GetType().FullName, contract.UnderlyingType.FullName)); - } - } - return token; } @@ -598,7 +589,7 @@ namespace LC.Newtonsoft.Json.Serialization throw JsonSerializationException.Create(reader, message); } - private bool ReadMetadataPropertiesToken(JTokenReader reader, ref Type? objectType, ref JsonContract? contract, JsonProperty? member, JsonContainerContract? containerContract, JsonProperty? containerMember, object? existingValue, out object? newValue, out string? id) + private bool ReadMetadataPropertiesToken(JTokenReader reader, ref Type? objectType, ref JsonContract? contract, JsonProperty? member, JsonContainerContract? containerContract, JsonProperty? containerMember, object? existingValue, [NotNullWhen(true)]out object? newValue, out string? id) { id = null; newValue = null; @@ -967,11 +958,7 @@ namespace LC.Newtonsoft.Json.Serialization { if (value is string s) { - return EnumUtils.ParseEnum( - contract.NonNullableUnderlyingType, - null, - s, - false); + return EnumUtils.ParseEnum(contract.NonNullableUnderlyingType, null, s, false); } if (ConvertUtils.IsInteger(primitiveContract.TypeCode)) { @@ -1400,7 +1387,7 @@ namespace LC.Newtonsoft.Json.Serialization { keyValue = DateTimeUtils.TryParseDateTime(keyValue.ToString(), reader.DateTimeZoneHandling, reader.DateFormatString, reader.Culture, out DateTime dt) ? dt - : EnsureType(reader, keyValue, CultureInfo.InvariantCulture, contract.KeyContract, contract.DictionaryKeyType)!; + : EnsureType(reader, keyValue, CultureInfo.InvariantCulture, contract.KeyContract!, contract.DictionaryKeyType)!; break; } #if HAVE_DATE_TIME_OFFSET @@ -1409,14 +1396,12 @@ namespace LC.Newtonsoft.Json.Serialization { keyValue = DateTimeUtils.TryParseDateTimeOffset(keyValue.ToString(), reader.DateFormatString, reader.Culture, out DateTimeOffset dt) ? dt - : EnsureType(reader, keyValue, CultureInfo.InvariantCulture, contract.KeyContract, contract.DictionaryKeyType)!; + : EnsureType(reader, keyValue, CultureInfo.InvariantCulture, contract.KeyContract!, contract.DictionaryKeyType)!; break; } #endif default: - keyValue = contract.KeyContract != null && contract.KeyContract.IsEnum - ? EnumUtils.ParseEnum(contract.KeyContract.NonNullableUnderlyingType, (Serializer._contractResolver as DefaultContractResolver)?.NamingStrategy, keyValue.ToString(), false) - : EnsureType(reader, keyValue, CultureInfo.InvariantCulture, contract.KeyContract, contract.DictionaryKeyType)!; + keyValue = EnsureType(reader, keyValue, CultureInfo.InvariantCulture, contract.KeyContract!, contract.DictionaryKeyType)!; break; } } @@ -2216,33 +2201,30 @@ namespace LC.Newtonsoft.Json.Serialization propertyValues.Add(creatorPropertyContext); JsonProperty? property = creatorPropertyContext.ConstructorProperty ?? creatorPropertyContext.Property; - if (property != null) + if (property != null && !property.Ignored) { - if (!property.Ignored) + if (property.PropertyContract == null) { - if (property.PropertyContract == null) - { - property.PropertyContract = GetContractSafe(property.PropertyType); - } - - JsonConverter? propertyConverter = GetConverter(property.PropertyContract, property.Converter, contract, containerProperty); - - if (!reader.ReadForType(property.PropertyContract, propertyConverter != null)) - { - throw JsonSerializationException.Create(reader, "Unexpected end when setting {0}'s value.".FormatWith(CultureInfo.InvariantCulture, memberName)); - } - - if (propertyConverter != null && propertyConverter.CanRead) - { - creatorPropertyContext.Value = DeserializeConvertable(propertyConverter, reader, property.PropertyType!, null); - } - else - { - creatorPropertyContext.Value = CreateValueInternal(reader, property.PropertyType, property.PropertyContract, property, contract, containerProperty, null); - } - - continue; + property.PropertyContract = GetContractSafe(property.PropertyType); } + + JsonConverter? propertyConverter = GetConverter(property.PropertyContract, property.Converter, contract, containerProperty); + + if (!reader.ReadForType(property.PropertyContract, propertyConverter != null)) + { + throw JsonSerializationException.Create(reader, "Unexpected end when setting {0}'s value.".FormatWith(CultureInfo.InvariantCulture, memberName)); + } + + if (propertyConverter != null && propertyConverter.CanRead) + { + creatorPropertyContext.Value = DeserializeConvertable(propertyConverter, reader, property.PropertyType!, null); + } + else + { + creatorPropertyContext.Value = CreateValueInternal(reader, property.PropertyType, property.PropertyContract, property, contract, containerProperty, null); + } + + continue; } else { diff --git a/Libs/Newtonsoft.Json.AOT/Serialization/JsonSerializerInternalWriter.cs b/Libs/Newtonsoft.Json.AOT/Serialization/JsonSerializerInternalWriter.cs index 3711477..6c4ec00 100644 --- a/Libs/Newtonsoft.Json.AOT/Serialization/JsonSerializerInternalWriter.cs +++ b/Libs/Newtonsoft.Json.AOT/Serialization/JsonSerializerInternalWriter.cs @@ -528,7 +528,7 @@ namespace LC.Newtonsoft.Json.Serialization OnSerialized(writer, contract, value); } - private bool CalculatePropertyValues(JsonWriter writer, object value, JsonContainerContract contract, JsonProperty? member, JsonProperty property, [NotNullWhen(true)]out JsonContract? memberContract, out object? memberValue) + private bool CalculatePropertyValues(JsonWriter writer, object value, JsonContainerContract contract, JsonProperty? member, JsonProperty property, [NotNullWhen(true)]out JsonContract? memberContract, [NotNullWhen(true)]out object? memberValue) { if (!property.Ignored && property.Readable && ShouldSerialize(writer, property, value) && IsSpecified(writer, property, value)) { @@ -542,14 +542,14 @@ namespace LC.Newtonsoft.Json.Serialization if (ShouldWriteProperty(memberValue, contract as JsonObjectContract, property)) { - if (ShouldWriteReference(memberValue, property, memberContract, contract, member)) + if (ShouldWriteReference(memberValue, property, memberContract!, contract, member)) { property.WritePropertyName(writer); WriteReference(writer, memberValue!); return false; } - if (!CheckForCircularReference(writer, memberValue, property, memberContract, contract, member)) + if (!CheckForCircularReference(writer, memberValue, property, memberContract!, contract, member)) { return false; } @@ -568,9 +568,7 @@ namespace LC.Newtonsoft.Json.Serialization } } -#pragma warning disable CS8762 // Parameter must have a non-null value when exiting in some condition. return true; -#pragma warning restore CS8762 // Parameter must have a non-null value when exiting in some condition. } } diff --git a/Libs/Newtonsoft.Json.AOT/Utilities/AsyncUtils.cs b/Libs/Newtonsoft.Json.AOT/Utilities/AsyncUtils.cs index dc4a5eb..6c070d8 100644 --- a/Libs/Newtonsoft.Json.AOT/Utilities/AsyncUtils.cs +++ b/Libs/Newtonsoft.Json.AOT/Utilities/AsyncUtils.cs @@ -61,9 +61,9 @@ namespace LC.Newtonsoft.Json.Utilities public static Task FromCanceled(this CancellationToken cancellationToken) { MiscellaneousUtils.Assert(cancellationToken.IsCancellationRequested); -#pragma warning disable CS8603 // Possible null reference return. +#pragma warning disable CS8653 // A default expression introduces a null value for a type parameter. return new Task(() => default, cancellationToken); -#pragma warning restore CS8603 // Possible null reference return. +#pragma warning restore CS8653 // A default expression introduces a null value for a type parameter. } // Task.Delay(0) is optimised as a cached task within the framework, and indeed diff --git a/Libs/Newtonsoft.Json.AOT/Utilities/DateTimeUtils.cs b/Libs/Newtonsoft.Json.AOT/Utilities/DateTimeUtils.cs index 5301d0f..ea45df5 100644 --- a/Libs/Newtonsoft.Json.AOT/Utilities/DateTimeUtils.cs +++ b/Libs/Newtonsoft.Json.AOT/Utilities/DateTimeUtils.cs @@ -179,9 +179,9 @@ namespace LC.Newtonsoft.Json.Utilities internal static long ConvertDateTimeToJavaScriptTicks(DateTime dateTime, TimeSpan offset) { - long universalTicks = ToUniversalTicks(dateTime, offset); + long universialTicks = ToUniversalTicks(dateTime, offset); - return UniversalTicksToJavaScriptTicks(universalTicks); + return UniversialTicksToJavaScriptTicks(universialTicks); } internal static long ConvertDateTimeToJavaScriptTicks(DateTime dateTime) @@ -193,12 +193,12 @@ namespace LC.Newtonsoft.Json.Utilities { long ticks = (convertToUtc) ? ToUniversalTicks(dateTime) : dateTime.Ticks; - return UniversalTicksToJavaScriptTicks(ticks); + return UniversialTicksToJavaScriptTicks(ticks); } - private static long UniversalTicksToJavaScriptTicks(long universalTicks) + private static long UniversialTicksToJavaScriptTicks(long universialTicks) { - long javaScriptTicks = (universalTicks - InitialJavaScriptDateTicks) / 10000; + long javaScriptTicks = (universialTicks - InitialJavaScriptDateTicks) / 10000; return javaScriptTicks; } @@ -822,4 +822,4 @@ namespace LC.Newtonsoft.Json.Utilities day = n - days[m - 1] + 1; } } -} +} \ No newline at end of file diff --git a/Libs/Newtonsoft.Json.AOT/Utilities/DictionaryWrapper.cs b/Libs/Newtonsoft.Json.AOT/Utilities/DictionaryWrapper.cs index 6120a0b..5fd7109 100644 --- a/Libs/Newtonsoft.Json.AOT/Utilities/DictionaryWrapper.cs +++ b/Libs/Newtonsoft.Json.AOT/Utilities/DictionaryWrapper.cs @@ -166,9 +166,7 @@ namespace LC.Newtonsoft.Json.Utilities } } -#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). - public bool TryGetValue(TKey key, out TValue? value) -#pragma warning restore CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). + public bool TryGetValue(TKey key, [MaybeNull]out TValue value) { if (_dictionary != null) { @@ -492,12 +490,8 @@ namespace LC.Newtonsoft.Json.Utilities #endif else { - // Consider changing this code to call GenericDictionary.Remove when value is null. - // #pragma warning disable CS8601 // Possible null reference assignment. -#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type. GenericDictionary[(TKey)key] = (TValue)value; -#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type. #pragma warning restore CS8601 // Possible null reference assignment. } } diff --git a/Libs/Newtonsoft.Json.AOT/Utilities/JavaScriptUtils.cs b/Libs/Newtonsoft.Json.AOT/Utilities/JavaScriptUtils.cs index 0efa3aa..4a01d45 100644 --- a/Libs/Newtonsoft.Json.AOT/Utilities/JavaScriptUtils.cs +++ b/Libs/Newtonsoft.Json.AOT/Utilities/JavaScriptUtils.cs @@ -629,7 +629,7 @@ namespace LC.Newtonsoft.Json.Utilities return true; } - private static bool TryGetDateConstructorValue(JsonReader reader, out long? integer, [NotNullWhen(false)] out string? errorMessage) + private static bool TryGetDateConstructorValue(JsonReader reader, out long? integer, out string? errorMessage) { integer = null; errorMessage = null; diff --git a/Libs/Newtonsoft.Json.AOT/Utilities/StringUtils.cs b/Libs/Newtonsoft.Json.AOT/Utilities/StringUtils.cs index 38f6fb4..035aaf8 100644 --- a/Libs/Newtonsoft.Json.AOT/Utilities/StringUtils.cs +++ b/Libs/Newtonsoft.Json.AOT/Utilities/StringUtils.cs @@ -195,7 +195,7 @@ namespace LC.Newtonsoft.Json.Utilities private static char ToLower(char c) { -#if HAVE_CHAR_TO_LOWER_WITH_CULTURE +#if HAVE_CHAR_TO_STRING_WITH_CULTURE c = char.ToLower(c, CultureInfo.InvariantCulture); #else c = char.ToLowerInvariant(c); diff --git a/csharp-sdk.sln b/csharp-sdk.sln index d6aab99..472f2d5 100644 --- a/csharp-sdk.sln +++ b/csharp-sdk.sln @@ -37,8 +37,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Storage.Test", "Storage\Sto EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LC.Google.Protobuf", "Libs\Google.Protobuf\LC.Google.Protobuf.csproj", "{B3BB497E-D654-4680-8312-ABCC12FFBBB2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LC.Newtonsoft.Json.AOT", "Libs\Newtonsoft.Json.AOT\LC.Newtonsoft.Json.AOT.csproj", "{ABE172EF-F120-4D69-AA67-5DF2C7FC4FFE}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LC.Newtonsoft.Json", "Libs\Newtonsoft.Json\LC.Newtonsoft.Json.csproj", "{9808CC82-171F-4046-A252-AA1C5C5BC222}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.AOT", "Common\Common.AOT\Common.AOT.csproj", "{BF90B92D-84D1-47DD-99D4-91C33A229FF9}" @@ -49,6 +47,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Realtime.AOT", "Realtime\Re EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiveQuery.AOT", "LiveQuery\LiveQuery.AOT\LiveQuery.AOT.csproj", "{5BE8789B-56C6-444F-87BF-F9447EE1E128}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LC.Newtonsoft.Json.AOT", "Libs\Newtonsoft.Json.AOT\LC.Newtonsoft.Json.AOT.csproj", "{531106D1-CFEA-4396-95F0-79EBCD85EAB1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -99,10 +99,6 @@ Global {B3BB497E-D654-4680-8312-ABCC12FFBBB2}.Debug|Any CPU.Build.0 = Debug|Any CPU {B3BB497E-D654-4680-8312-ABCC12FFBBB2}.Release|Any CPU.ActiveCfg = Release|Any CPU {B3BB497E-D654-4680-8312-ABCC12FFBBB2}.Release|Any CPU.Build.0 = Release|Any CPU - {ABE172EF-F120-4D69-AA67-5DF2C7FC4FFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ABE172EF-F120-4D69-AA67-5DF2C7FC4FFE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {ABE172EF-F120-4D69-AA67-5DF2C7FC4FFE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ABE172EF-F120-4D69-AA67-5DF2C7FC4FFE}.Release|Any CPU.Build.0 = Release|Any CPU {9808CC82-171F-4046-A252-AA1C5C5BC222}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9808CC82-171F-4046-A252-AA1C5C5BC222}.Debug|Any CPU.Build.0 = Debug|Any CPU {9808CC82-171F-4046-A252-AA1C5C5BC222}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -123,6 +119,10 @@ Global {5BE8789B-56C6-444F-87BF-F9447EE1E128}.Debug|Any CPU.Build.0 = Debug|Any CPU {5BE8789B-56C6-444F-87BF-F9447EE1E128}.Release|Any CPU.ActiveCfg = Release|Any CPU {5BE8789B-56C6-444F-87BF-F9447EE1E128}.Release|Any CPU.Build.0 = Release|Any CPU + {531106D1-CFEA-4396-95F0-79EBCD85EAB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {531106D1-CFEA-4396-95F0-79EBCD85EAB1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {531106D1-CFEA-4396-95F0-79EBCD85EAB1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {531106D1-CFEA-4396-95F0-79EBCD85EAB1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {4194FE34-327C-42C2-971F-6B07904E20A5} = {076871D0-BE1F-4AF0-B83E-697C71C0C3B3} @@ -136,12 +136,12 @@ Global {0A6AEBC9-9A36-4EA7-8F58-8B951126092D} = {8087ABCD-629C-4EE5-9ECE-8BDAE631236F} {07B8BAE6-CA9A-48B0-9881-F63F1F5DCE70} = {076871D0-BE1F-4AF0-B83E-697C71C0C3B3} {B3BB497E-D654-4680-8312-ABCC12FFBBB2} = {3B53EFFB-6962-4EED-88FD-F9D6E9650A2D} - {ABE172EF-F120-4D69-AA67-5DF2C7FC4FFE} = {3B53EFFB-6962-4EED-88FD-F9D6E9650A2D} {9808CC82-171F-4046-A252-AA1C5C5BC222} = {3B53EFFB-6962-4EED-88FD-F9D6E9650A2D} {BF90B92D-84D1-47DD-99D4-91C33A229FF9} = {375B854F-C239-4503-868A-7F04C40582E5} {81A5200F-6992-4BF5-883B-CE207E6E97DB} = {076871D0-BE1F-4AF0-B83E-697C71C0C3B3} {84C9B97C-B084-447A-921F-4F1977F23C94} = {319A9989-3B69-4AD0-9E43-F6D31C1D2A4A} {5BE8789B-56C6-444F-87BF-F9447EE1E128} = {A1A24E0F-6901-4A9A-9BB8-4F586BC7EE17} + {531106D1-CFEA-4396-95F0-79EBCD85EAB1} = {3B53EFFB-6962-4EED-88FD-F9D6E9650A2D} EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution version = 0.7.1