chore: Newtonsoft.Json.AOT 12.0.201
parent
3a0b247817
commit
b59b3028c6
|
@ -587,7 +587,7 @@ namespace LC.Newtonsoft.Json
|
|||
/// A JSON string representation of the object.
|
||||
/// </returns>
|
||||
[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
|
|||
/// <param name="value">The JSON to deserialize.</param>
|
||||
/// <returns>The deserialized object from the JSON string.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public static T? DeserializeObject<T>(string value)
|
||||
public static T DeserializeObject<T>(string value)
|
||||
{
|
||||
return DeserializeObject<T>(value, (JsonSerializerSettings?)null);
|
||||
}
|
||||
|
@ -732,7 +732,7 @@ namespace LC.Newtonsoft.Json
|
|||
/// <param name="anonymousTypeObject">The anonymous type object.</param>
|
||||
/// <returns>The deserialized anonymous type from the JSON string.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public static T? DeserializeAnonymousType<T>(string value, T anonymousTypeObject)
|
||||
public static T DeserializeAnonymousType<T>(string value, T anonymousTypeObject)
|
||||
{
|
||||
return DeserializeObject<T>(value);
|
||||
}
|
||||
|
@ -753,7 +753,7 @@ namespace LC.Newtonsoft.Json
|
|||
/// </param>
|
||||
/// <returns>The deserialized anonymous type from the JSON string.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public static T? DeserializeAnonymousType<T>(string value, T anonymousTypeObject, JsonSerializerSettings settings)
|
||||
public static T DeserializeAnonymousType<T>(string value, T anonymousTypeObject, JsonSerializerSettings settings)
|
||||
{
|
||||
return DeserializeObject<T>(value, settings);
|
||||
}
|
||||
|
@ -766,9 +766,12 @@ namespace LC.Newtonsoft.Json
|
|||
/// <param name="converters">Converters to use while deserializing.</param>
|
||||
/// <returns>The deserialized object from the JSON string.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public static T? DeserializeObject<T>(string value, params JsonConverter[] converters)
|
||||
[return: MaybeNull]
|
||||
public static T DeserializeObject<T>(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.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -782,9 +785,12 @@ namespace LC.Newtonsoft.Json
|
|||
/// </param>
|
||||
/// <returns>The deserialized object from the JSON string.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public static T? DeserializeObject<T>(string value, JsonSerializerSettings? settings)
|
||||
[return: MaybeNull]
|
||||
public static T DeserializeObject<T>(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.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -103,7 +105,7 @@ namespace LC.Newtonsoft.Json
|
|||
/// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <param name="serializer">The calling serializer.</param>
|
||||
public abstract void WriteJson(JsonWriter writer, T? value, JsonSerializer serializer);
|
||||
public abstract void WriteJson(JsonWriter writer, [AllowNull]T value, JsonSerializer serializer);
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -132,7 +136,7 @@ namespace LC.Newtonsoft.Json
|
|||
/// <param name="hasExistingValue">The existing value has a value.</param>
|
||||
/// <param name="serializer">The calling serializer.</param>
|
||||
/// <returns>The object value.</returns>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this instance can convert the specified object type.
|
||||
|
|
|
@ -227,8 +227,6 @@ namespace LC.Newtonsoft.Json
|
|||
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum depth allowed when reading JSON. Reading past this depth will throw a <see cref="JsonReaderException"/>.
|
||||
/// A null value means there is no maximum.
|
||||
/// The default value is <c>128</c>.
|
||||
/// </summary>
|
||||
public int? MaxDepth
|
||||
{
|
||||
|
@ -329,7 +327,6 @@ namespace LC.Newtonsoft.Json
|
|||
_dateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
|
||||
_dateParseHandling = DateParseHandling.DateTime;
|
||||
_floatParseHandling = FloatParseHandling.Double;
|
||||
_maxDepth = 64;
|
||||
|
||||
CloseInput = true;
|
||||
}
|
||||
|
|
|
@ -514,7 +514,7 @@ namespace LC.Newtonsoft.Json
|
|||
/// <summary>
|
||||
/// Gets or sets the maximum depth allowed when reading JSON. Reading past this depth will throw a <see cref="JsonReaderException"/>.
|
||||
/// A null value means there is no maximum.
|
||||
/// The default value is <c>128</c>.
|
||||
/// The default value is <c>null</c>.
|
||||
/// </summary>
|
||||
public virtual int? MaxDepth
|
||||
{
|
||||
|
@ -865,9 +865,12 @@ namespace LC.Newtonsoft.Json
|
|||
/// <typeparam name="T">The type of the object to deserialize.</typeparam>
|
||||
/// <returns>The instance of <typeparamref name="T"/> being deserialized.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public T? Deserialize<T>(JsonReader reader)
|
||||
[return: MaybeNull]
|
||||
public T Deserialize<T>(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.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -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
|
|||
/// <summary>
|
||||
/// Gets or sets the maximum depth allowed when reading JSON. Reading past this depth will throw a <see cref="JsonReaderException"/>.
|
||||
/// A null value means there is no maximum.
|
||||
/// The default value is <c>128</c>.
|
||||
/// The default value is <c>null</c>.
|
||||
/// </summary>
|
||||
public int? MaxDepth
|
||||
{
|
||||
get => _maxDepthSet ? _maxDepth : DefaultMaxDepth;
|
||||
get => _maxDepth;
|
||||
set
|
||||
{
|
||||
if (value <= 0)
|
||||
|
|
|
@ -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<State[]> allStates = StateArrayTemplate.ToList();
|
||||
State[] errorStates = StateArrayTemplate[0];
|
||||
State[] valueStates = StateArrayTemplate[7];
|
||||
List<State[]> 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));
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<LibraryFrameworks>netstandard2.0</LibraryFrameworks>
|
||||
<UnityBuild>AOT</UnityBuild>
|
||||
<TargetFrameworks Condition="'$(LibraryFrameworks)'==''">netstandard2.0</TargetFrameworks>
|
||||
<TargetFrameworks Condition="'$(LibraryFrameworks)'==''">netstandard2.0;net45;portable-net45+win8+wpa81+wp8</TargetFrameworks>
|
||||
<TargetFrameworks Condition="'$(LibraryFrameworks)'!=''">$(LibraryFrameworks)</TargetFrameworks>
|
||||
<LangVersion>9.0</LangVersion>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<!-- version numbers will be updated by build -->
|
||||
<AssemblyVersion>11.0.0.0</AssemblyVersion>
|
||||
<FileVersion>11.0.1</FileVersion>
|
||||
|
@ -38,18 +39,17 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="**\*.orig" />
|
||||
<EmbeddedResource Include="Resources\link.xml">
|
||||
<LogicalName>Newtonsoft.Json.xml</LogicalName>
|
||||
</EmbeddedResource>
|
||||
<None Include="..\..\LICENSE.md" Pack="true" PackagePath="LICENSE.md" />
|
||||
<None Include="$(PackageIconFullPath)" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="$(MicrosoftCodeAnalysisNetAnalyzersPackageVersion)" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="$(MicrosoftCodeAnalysisFxCopAnalyzersPackageVersion)" PrivateAssets="All" />
|
||||
<!-- Compiler to support nullable in non-preview VS2019 -->
|
||||
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="$(MicrosoftNetCompilersToolsetPackageVersion)" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition="'$(UnityBuild)'=='Tests' OR ('$(UnityBuild)'=='' AND '$(TargetFramework)'=='net46')">
|
||||
<PropertyGroup Condition="'$(UnityBuild)'=='Tests' OR ('$(UnityBuild)'=='' AND '$(TargetFramework)'=='net45')">
|
||||
<!-- Only used in Unity Tests & Newtonsoft.Json.Tests -->
|
||||
<TargetFramework>net46</TargetFramework>
|
||||
<TargetFramework>net45</TargetFramework>
|
||||
<AssemblyTitle>Json.NET for Unity tests (NOT FOR PRODUCTION)</AssemblyTitle>
|
||||
<DefineConstants>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)</DefineConstants>
|
||||
<OutputPath>bin\$(Configuration)\unity-tests</OutputPath>
|
||||
|
@ -75,7 +75,19 @@
|
|||
<DefineConstants>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)</DefineConstants>
|
||||
<OutputPath>bin\$(Configuration)\unity-aot</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(UnityBuild)'=='Portable' OR '$(TargetFramework)'=='portable-net45+win8+wpa81+wp8'">
|
||||
<!-- Unity portable (WP8, UWP, ...) build -->
|
||||
<TargetFramework>portable-net45+win8+wpa81+wp8</TargetFramework>
|
||||
<AssemblyTitle>Json.NET for Unity portable (wp8)</AssemblyTitle>
|
||||
<DefineConstants>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)</DefineConstants>
|
||||
<TargetFrameworkIdentifier>.NETPortable</TargetFrameworkIdentifier>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>Profile259</TargetFrameworkProfile>
|
||||
<NugetTargetMoniker>.NETPortable,Version=v0.0,Profile=Profile259</NugetTargetMoniker>
|
||||
<LanguageTargets>$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets</LanguageTargets>
|
||||
<OutputPath>bin\$(Configuration)\unity-portable-net45</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DefineConstants>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)</DefineConstants>
|
||||
<DefineConstants>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;</DefineConstants>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
|
@ -115,7 +115,7 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="JToken"/> that contains the values of every token in the source collection with the given key.</returns>
|
||||
public static IJEnumerable<JToken> Values(this IEnumerable<JToken> source, object? key)
|
||||
{
|
||||
return Values<JToken, JToken>(source, key)!.AsJEnumerable();
|
||||
return Values<JToken, JToken>(source, key).AsJEnumerable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -135,7 +135,7 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
/// <param name="source">An <see cref="IEnumerable{T}"/> of <see cref="JToken"/> that contains the source collection.</param>
|
||||
/// <param name="key">The token key.</param>
|
||||
/// <returns>An <see cref="IEnumerable{T}"/> that contains the converted values of every token in the source collection with the given key.</returns>
|
||||
public static IEnumerable<U?> Values<U>(this IEnumerable<JToken> source, object key)
|
||||
public static IEnumerable<U> Values<U>(this IEnumerable<JToken> source, object key)
|
||||
{
|
||||
return Values<JToken, U>(source, key);
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
/// <typeparam name="U">The type to convert the values to.</typeparam>
|
||||
/// <param name="source">An <see cref="IEnumerable{T}"/> of <see cref="JToken"/> that contains the source collection.</param>
|
||||
/// <returns>An <see cref="IEnumerable{T}"/> that contains the converted values of every token in the source collection.</returns>
|
||||
public static IEnumerable<U?> Values<U>(this IEnumerable<JToken> source)
|
||||
public static IEnumerable<U> Values<U>(this IEnumerable<JToken> source)
|
||||
{
|
||||
return Values<JToken, U>(source, null);
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
/// <typeparam name="U">The type to convert the value to.</typeparam>
|
||||
/// <param name="value">A <see cref="JToken"/> cast as a <see cref="IEnumerable{T}"/> of <see cref="JToken"/>.</param>
|
||||
/// <returns>A converted value.</returns>
|
||||
public static U? Value<U>(this IEnumerable<JToken> value)
|
||||
public static U Value<U>(this IEnumerable<JToken> value)
|
||||
{
|
||||
return value.Value<JToken, U>();
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
/// <typeparam name="U">The type to convert the value to.</typeparam>
|
||||
/// <param name="value">A <see cref="JToken"/> cast as a <see cref="IEnumerable{T}"/> of <see cref="JToken"/>.</param>
|
||||
/// <returns>A converted value.</returns>
|
||||
public static U? Value<T, U>(this IEnumerable<T> value) where T : JToken
|
||||
public static U Value<T, U>(this IEnumerable<T> value) where T : JToken
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||
|
||||
|
@ -181,7 +181,7 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
return token.Convert<JToken, U>();
|
||||
}
|
||||
|
||||
internal static IEnumerable<U?> Values<T, U>(this IEnumerable<T> source, object? key) where T : JToken
|
||||
internal static IEnumerable<U> Values<T, U>(this IEnumerable<T> source, object? key) where T : JToken
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(source, nameof(source));
|
||||
|
||||
|
@ -226,7 +226,7 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="JToken"/> that contains the values of every token in the source collection.</returns>
|
||||
public static IJEnumerable<JToken> Children<T>(this IEnumerable<T> source) where T : JToken
|
||||
{
|
||||
return Children<T, JToken>(source)!.AsJEnumerable();
|
||||
return Children<T, JToken>(source).AsJEnumerable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -236,14 +236,14 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
/// <typeparam name="U">The type to convert the values to.</typeparam>
|
||||
/// <typeparam name="T">The source collection type.</typeparam>
|
||||
/// <returns>An <see cref="IEnumerable{T}"/> that contains the converted values of every token in the source collection.</returns>
|
||||
public static IEnumerable<U?> Children<T, U>(this IEnumerable<T> source) where T : JToken
|
||||
public static IEnumerable<U> Children<T, U>(this IEnumerable<T> source) where T : JToken
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(source, nameof(source));
|
||||
|
||||
return source.SelectMany(c => c.Children()).Convert<JToken, U>();
|
||||
}
|
||||
|
||||
internal static IEnumerable<U?> Convert<T, U>(this IEnumerable<T> source) where T : JToken
|
||||
internal static IEnumerable<U> Convert<T, U>(this IEnumerable<T> source) where T : JToken
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(source, nameof(source));
|
||||
|
||||
|
@ -253,7 +253,8 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
}
|
||||
}
|
||||
|
||||
internal static U? Convert<T, U>(this T token) where T : JToken?
|
||||
[return: MaybeNull]
|
||||
internal static U Convert<T, U>(this T token) where T : JToken?
|
||||
{
|
||||
if (token == null)
|
||||
{
|
||||
|
|
|
@ -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
|
|||
/// <returns>
|
||||
/// A <see cref="IEnumerable{T}"/> containing the child values of this <see cref="JToken"/>, in document order.
|
||||
/// </returns>
|
||||
public override IEnumerable<T?> Values<T>() where T : default
|
||||
public override IEnumerable<T> Values<T>()
|
||||
{
|
||||
return ChildrenTokens.Convert<JToken, T>();
|
||||
}
|
||||
|
@ -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<JToken> 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
|
|||
/// <param name="content">The content to be added.</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -654,10 +645,10 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
/// <param name="content">The content to be added.</param>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
return JEnumerable<JToken>.Empty;
|
||||
}
|
||||
|
||||
return new JEnumerable<JToken>(_enumerable.Values<T, JToken>(key)!);
|
||||
return new JEnumerable<JToken>(_enumerable.Values<T, JToken>(key));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -255,7 +255,7 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
}
|
||||
|
||||
int index = _parent.IndexOfItem(this);
|
||||
_parent.TryAddInternal(index, content, false);
|
||||
_parent.AddInternal(index, content, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -334,7 +334,7 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
/// <typeparam name="T">The type to convert the token to.</typeparam>
|
||||
/// <param name="key">The token key.</param>
|
||||
/// <returns>The converted token value.</returns>
|
||||
public virtual T? Value<T>(object key)
|
||||
public virtual T Value<T>(object key)
|
||||
{
|
||||
JToken? token = this[key];
|
||||
|
||||
|
@ -378,7 +378,7 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
/// </summary>
|
||||
/// <typeparam name="T">The type to convert the values to.</typeparam>
|
||||
/// <returns>A <see cref="IEnumerable{T}"/> containing the child values of this <see cref="JToken"/>, in document order.</returns>
|
||||
public virtual IEnumerable<T?> Values<T>()
|
||||
public virtual IEnumerable<T> Values<T>()
|
||||
{
|
||||
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
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="System.Boolean"/>.
|
||||
/// </summary>
|
||||
|
@ -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
|
||||
/// <summary>
|
||||
/// Performs an implicit conversion from <see cref="Boolean"/> to <see cref="JToken"/>.
|
||||
/// </summary>
|
||||
|
@ -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
|
|||
/// </summary>
|
||||
/// <typeparam name="T">The object type that the token will be deserialized to.</typeparam>
|
||||
/// <returns>The new object created from the JSON value.</returns>
|
||||
public T? ToObject<T>()
|
||||
[return: MaybeNull]
|
||||
public T ToObject<T>()
|
||||
{
|
||||
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.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -2062,9 +2065,12 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
/// <typeparam name="T">The object type that the token will be deserialized to.</typeparam>
|
||||
/// <param name="jsonSerializer">The <see cref="JsonSerializer"/> that will be used when creating the object.</param>
|
||||
/// <returns>The new object created from the JSON value.</returns>
|
||||
public T? ToObject<T>(JsonSerializer jsonSerializer)
|
||||
[return: MaybeNull]
|
||||
public T ToObject<T>(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.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -2307,7 +2313,7 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
/// <returns>A <see cref="JToken"/>, or <c>null</c>.</returns>
|
||||
public JToken? SelectToken(string path)
|
||||
{
|
||||
return SelectToken(path, settings: null);
|
||||
return SelectToken(path, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -2319,28 +2325,11 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
/// <param name="errorWhenNoMatch">A flag to indicate whether an error should be thrown if no tokens are found when evaluating part of the expression.</param>
|
||||
/// <returns>A <see cref="JToken"/>.</returns>
|
||||
public JToken? SelectToken(string path, bool errorWhenNoMatch)
|
||||
{
|
||||
JsonSelectSettings? settings = errorWhenNoMatch
|
||||
? new JsonSelectSettings { ErrorWhenNoMatch = true }
|
||||
: null;
|
||||
|
||||
return SelectToken(path, settings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selects a <see cref="JToken"/> using a JSONPath expression. Selects the token that matches the object path.
|
||||
/// </summary>
|
||||
/// <param name="path">
|
||||
/// A <see cref="String"/> that contains a JSONPath expression.
|
||||
/// </param>
|
||||
/// <param name="settings">The <see cref="JsonSelectSettings"/> used to select tokens.</param>
|
||||
/// <returns>A <see cref="JToken"/>.</returns>
|
||||
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
|
|||
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="JToken"/> that contains the selected elements.</returns>
|
||||
public IEnumerable<JToken> SelectTokens(string path)
|
||||
{
|
||||
return SelectTokens(path, settings: null);
|
||||
return SelectTokens(path, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -2375,25 +2364,8 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="JToken"/> that contains the selected elements.</returns>
|
||||
public IEnumerable<JToken> SelectTokens(string path, bool errorWhenNoMatch)
|
||||
{
|
||||
JsonSelectSettings? settings = errorWhenNoMatch
|
||||
? new JsonSelectSettings { ErrorWhenNoMatch = true }
|
||||
: null;
|
||||
|
||||
return SelectTokens(path, settings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selects a collection of elements using a JSONPath expression.
|
||||
/// </summary>
|
||||
/// <param name="path">
|
||||
/// A <see cref="String"/> that contains a JSONPath expression.
|
||||
/// </param>
|
||||
/// <param name="settings">The <see cref="JsonSelectSettings"/> used to select tokens.</param>
|
||||
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="JToken"/> that contains the selected elements.</returns>
|
||||
public IEnumerable<JToken> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -196,11 +196,7 @@ 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))
|
||||
{
|
||||
_parent.Add(value);
|
||||
_current = _parent.Last;
|
||||
|
||||
if (_parent.Type == JTokenType.Property)
|
||||
|
@ -208,7 +204,6 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
_parent = _parent.Parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_value = value ?? JValue.CreateNull();
|
||||
|
|
|
@ -64,7 +64,6 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
public JValue(JValue other)
|
||||
: this(other.Value, other.Type)
|
||||
{
|
||||
CopyAnnotations(this, other);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -842,7 +841,7 @@ namespace LC.Newtonsoft.Json.Linq
|
|||
/// <c>true</c> if the current object is equal to the <paramref name="other"/> parameter; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
/// <param name="other">An object to compare with this object.</param>
|
||||
public bool Equals(JValue? other)
|
||||
public bool Equals([AllowNull] JValue other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
|
|
|
@ -8,13 +8,13 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath
|
|||
{
|
||||
public int? Index { get; set; }
|
||||
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, JsonSelectSettings? settings)
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> 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));
|
||||
}
|
||||
|
|
|
@ -11,13 +11,13 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath
|
|||
Indexes = indexes;
|
||||
}
|
||||
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, JsonSelectSettings? settings)
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> 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)
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath
|
|||
public int? End { get; set; }
|
||||
public int? Step { get; set; }
|
||||
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, JsonSelectSettings? settings)
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> 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));
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath
|
|||
Name = name;
|
||||
}
|
||||
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, JsonSelectSettings? settings)
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> 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));
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath
|
|||
Names = names;
|
||||
}
|
||||
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, JsonSelectSettings? settings)
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> 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
|
||||
|
|
|
@ -874,17 +874,17 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath
|
|||
}
|
||||
}
|
||||
|
||||
internal IEnumerable<JToken> Evaluate(JToken root, JToken t, JsonSelectSettings? settings)
|
||||
internal IEnumerable<JToken> Evaluate(JToken root, JToken t, bool errorWhenNoMatch)
|
||||
{
|
||||
return Evaluate(Filters, root, t, settings);
|
||||
return Evaluate(Filters, root, t, errorWhenNoMatch);
|
||||
}
|
||||
|
||||
internal static IEnumerable<JToken> Evaluate(List<PathFilter> filters, JToken root, JToken t, JsonSelectSettings? settings)
|
||||
internal static IEnumerable<JToken> Evaluate(List<PathFilter> filters, JToken root, JToken t, bool errorWhenNoMatch)
|
||||
{
|
||||
IEnumerable<JToken> current = new[] { t };
|
||||
foreach (PathFilter filter in filters)
|
||||
{
|
||||
current = filter.ExecuteFilter(root, current, settings);
|
||||
current = filter.ExecuteFilter(root, current, errorWhenNoMatch);
|
||||
}
|
||||
|
||||
return current;
|
||||
|
|
|
@ -6,15 +6,15 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath
|
|||
{
|
||||
internal abstract class PathFilter
|
||||
{
|
||||
public abstract IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, JsonSelectSettings? settings);
|
||||
public abstract IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> 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));
|
||||
}
|
||||
|
|
|
@ -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<QueryExpression>();
|
||||
}
|
||||
|
||||
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<PathFilter> pathFilters)
|
||||
{
|
||||
return JPath.Evaluate(pathFilters, root, t, null);
|
||||
return JPath.Evaluate(pathFilters, root, t, false);
|
||||
}
|
||||
|
||||
return CollectionUtils.ArrayEmpty<JToken>();
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -12,13 +12,13 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath
|
|||
Expression = expression;
|
||||
}
|
||||
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, JsonSelectSettings? settings)
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> 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;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath
|
|||
Expression = expression;
|
||||
}
|
||||
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, JsonSelectSettings? settings)
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> 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;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath
|
|||
{
|
||||
}
|
||||
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, JsonSelectSettings? settings)
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
{
|
||||
return new[] { root };
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath
|
|||
Name = name;
|
||||
}
|
||||
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, JsonSelectSettings? settings)
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
{
|
||||
foreach (JToken c in current)
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace LC.Newtonsoft.Json.Linq.JsonPath
|
|||
_names = names;
|
||||
}
|
||||
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, JsonSelectSettings? settings)
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
{
|
||||
foreach (JToken c in current)
|
||||
{
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace LC.Newtonsoft.Json.Linq
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the settings used when selecting JSON.
|
||||
/// </summary>
|
||||
public class JsonSelectSettings
|
||||
{
|
||||
#if HAVE_REGEX_TIMEOUTS
|
||||
/// <summary>
|
||||
/// Gets or sets a timeout that will be used when executing regular expressions.
|
||||
/// </summary>
|
||||
/// <value>The timeout that will be used when executing regular expressions.</value>
|
||||
public TimeSpan? RegexMatchTimeout { get; set; }
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a flag that indicates whether an error should be thrown if
|
||||
/// no tokens are found when evaluating part of the expression.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A flag that indicates whether an error should be thrown if
|
||||
/// no tokens are found when evaluating part of the expression.
|
||||
/// </value>
|
||||
public bool ErrorWhenNoMatch { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
<linker>
|
||||
<assembly fullname="System">
|
||||
<!-- No issue on these, though they are quite commonly used. -->
|
||||
<type fullname="System.ComponentModel.*Converter" preserve="all"/>
|
||||
</assembly>
|
||||
<assembly fullname="Newtonsoft.Json">
|
||||
<!-- https://github.com/jilleJr/Newtonsoft.Json-for-Unity/issues/54 -->
|
||||
<type fullname="System.Runtime.CompilerServices.NullableAttribute"/>
|
||||
<type fullname="System.Runtime.CompilerServices.NullableContextAttribute"/>
|
||||
|
||||
<!-- https://github.com/jilleJr/Newtonsoft.Json-for-Unity/issues/8 -->
|
||||
<!-- https://github.com/jilleJr/Newtonsoft.Json-for-Unity/issues/65 -->
|
||||
<type fullname="Newtonsoft.Json.Converters.*Converter" preserve="all" />
|
||||
|
||||
<!-- No issue on these, though they are quite commonly used. -->
|
||||
<type fullname="Newtonsoft.Json.Serialization.*NamingStrategy" preserve="all" />
|
||||
</assembly>
|
||||
</linker>
|
|
@ -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<object, object>);
|
||||
}
|
||||
|
@ -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,
|
||||
|
|
|
@ -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,9 +2201,7 @@ namespace LC.Newtonsoft.Json.Serialization
|
|||
propertyValues.Add(creatorPropertyContext);
|
||||
|
||||
JsonProperty? property = creatorPropertyContext.ConstructorProperty ?? creatorPropertyContext.Property;
|
||||
if (property != null)
|
||||
{
|
||||
if (!property.Ignored)
|
||||
if (property != null && !property.Ignored)
|
||||
{
|
||||
if (property.PropertyContract == null)
|
||||
{
|
||||
|
@ -2243,7 +2226,6 @@ namespace LC.Newtonsoft.Json.Serialization
|
|||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!reader.Read())
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,9 +61,9 @@ namespace LC.Newtonsoft.Json.Utilities
|
|||
public static Task<T> FromCanceled<T>(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<T>(() => 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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue