Justification = "The ctor is marked RequiresUnreferencedCode.")]
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
{
- ConstructorInfo? constructor;
JsonConverter converter;
Type converterType;
- if (typeToConvert.IsKeyValuePair())
- {
- // browser-wasm compat -- ensure the linker doesn't trim away constructor parameter names from KVP.
- Type[] genericArguments = typeToConvert.GetGenericArguments();
- Type keyValuePairType = typeof(KeyValuePair<,>).MakeGenericType(genericArguments);
- constructor = keyValuePairType.GetConstructor(genericArguments);
- }
- else if (!typeToConvert.TryGetDeserializationConstructor(_useDefaultConstructorInUnannotatedStructs, out constructor))
+ bool useDefaultConstructorInUnannotatedStructs = _useDefaultConstructorInUnannotatedStructs && !typeToConvert.IsKeyValuePair();
+ if (!typeToConvert.TryGetDeserializationConstructor(useDefaultConstructorInUnannotatedStructs, out ConstructorInfo? constructor))
{
ThrowHelper.ThrowInvalidOperationException_SerializationDuplicateTypeAttribute<JsonConstructorAttribute>(typeToConvert);
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Collections.Generic;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text.Json.Nodes;
{
public abstract partial class JsonSerializerWrapper
{
+ // Ensure that the reflection-based serializer testing abstraction roots KeyValuePair<,>
+ // which is required by many tests in the reflection test suite.
+ [DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicProperties, typeof(KeyValuePair<,>))]
+ protected JsonSerializerWrapper()
+ {
+ }
+
public static JsonSerializerWrapper SpanSerializer { get; } = new SpanSerializerWrapper();
public static JsonSerializerWrapper StringSerializer { get; } = new StringSerializerWrapper();
public static StreamingJsonSerializerWrapper AsyncStreamSerializer { get; } = new AsyncStreamSerializerWrapper();