LargeObjectWithParameterizedConstructorConverter<T>
class LargeObjectWithParameterizedConstructorConverter<T> : ObjectWithParameterizedConstructorConverter<T>
using System.Buffers;
using System.Runtime.CompilerServices;
using System.Text.Json.Serialization.Metadata;
namespace System.Text.Json.Serialization.Converters
{
internal class LargeObjectWithParameterizedConstructorConverter<T> : ObjectWithParameterizedConstructorConverter<T>
{
protected sealed override bool ReadAndCacheConstructorArgument([System.Runtime.CompilerServices.ScopedRef] ref ReadStack state, ref Utf8JsonReader reader, JsonParameterInfo jsonParameterInfo)
{
object value;
bool num = jsonParameterInfo.EffectiveConverter.TryReadAsObject(ref reader, jsonParameterInfo.ParameterType, jsonParameterInfo.Options, ref state, out value);
if (num && (value != null || !jsonParameterInfo.IgnoreNullTokensOnRead)) {
if (value == null && !jsonParameterInfo.IsNullable && jsonParameterInfo.Options.RespectNullableAnnotations)
ThrowHelper.ThrowJsonException_ConstructorParameterDisallowNull(jsonParameterInfo.Name, state.Current.JsonTypeInfo.Type);
((object[])state.Current.CtorArgumentState.Arguments)[jsonParameterInfo.Position] = value;
}
return num;
}
protected sealed override object CreateObject(ref ReadStackFrame frame)
{
object[] array = (object[])frame.CtorArgumentState.Arguments;
frame.CtorArgumentState.Arguments = null;
object result = ((Func<object[], T>)frame.JsonTypeInfo.CreateObjectWithArgs)(array);
ArrayPool<object>.Shared.Return(array, true);
return result;
}
protected sealed override void InitializeConstructorArgumentCaches(ref ReadStack state, JsonSerializerOptions options)
{
JsonTypeInfo jsonTypeInfo = state.Current.JsonTypeInfo;
ArrayPool<object> shared = ArrayPool<object>.Shared;
ReadOnlySpan<JsonParameterInfo> parameterCache = jsonTypeInfo.ParameterCache;
object[] array = shared.Rent(parameterCache.Length);
parameterCache = jsonTypeInfo.ParameterCache;
foreach (JsonParameterInfo jsonParameterInfo in parameterCache) {
array[jsonParameterInfo.Position] = jsonParameterInfo.EffectiveDefaultValue;
}
state.Current.CtorArgumentState.Arguments = array;
}
}
}