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