< Summary

Information
Line coverage
0%
Covered lines: 0
Uncovered lines: 31
Coverable lines: 31
Total lines: 66
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 14
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
ReadAndCacheConstructorArgument(...)0%12120%
CreateObject(...)100%110%
InitializeConstructorArgumentCaches(...)0%220%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Large.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Buffers;
 5using System.Collections.Generic;
 6using System.Diagnostics;
 7using System.Text.Json.Serialization.Metadata;
 8
 9namespace System.Text.Json.Serialization.Converters
 10{
 11    /// <summary>
 12    /// Implementation of <cref>JsonObjectConverter{T}</cref> that supports the deserialization
 13    /// of JSON objects using parameterized constructors.
 14    /// </summary>
 15    internal class LargeObjectWithParameterizedConstructorConverter<T> : ObjectWithParameterizedConstructorConverter<T> 
 16    {
 17        protected sealed override bool ReadAndCacheConstructorArgument(scoped ref ReadStack state, ref Utf8JsonReader re
 018        {
 019            Debug.Assert(jsonParameterInfo.ShouldDeserialize);
 20
 021            bool success = jsonParameterInfo.EffectiveConverter.TryReadAsObject(ref reader, jsonParameterInfo.ParameterT
 22
 023            if (success && !(arg is null && jsonParameterInfo.IgnoreNullTokensOnRead))
 024            {
 025                if (arg is null && !jsonParameterInfo.IsNullable && jsonParameterInfo.Options.RespectNullableAnnotations
 026                {
 027                    ThrowHelper.ThrowJsonException_ConstructorParameterDisallowNull(jsonParameterInfo.Name, state.Curren
 28                }
 29
 030                ((object[])state.Current.CtorArgumentState!.Arguments)[jsonParameterInfo.Position] = arg!;
 031            }
 32
 033            return success;
 034        }
 35
 36        protected sealed override object CreateObject(ref ReadStackFrame frame)
 037        {
 038            Debug.Assert(frame.CtorArgumentState is not null);
 039            Debug.Assert(frame.JsonTypeInfo.CreateObjectWithArgs is not null);
 40
 041            object[] arguments = (object[])frame.CtorArgumentState.Arguments;
 042            frame.CtorArgumentState.Arguments = null!;
 43
 044            Func<object[], T> createObject = (Func<object[], T>)frame.JsonTypeInfo.CreateObjectWithArgs;
 45
 046            object obj = createObject(arguments);
 47
 048            ArrayPool<object>.Shared.Return(arguments, clearArray: true);
 049            return obj;
 050        }
 51
 52        protected sealed override void InitializeConstructorArgumentCaches(ref ReadStack state, JsonSerializerOptions op
 053        {
 054            JsonTypeInfo typeInfo = state.Current.JsonTypeInfo;
 55
 056            object?[] arguments = ArrayPool<object>.Shared.Rent(typeInfo.ParameterCache.Length);
 057            foreach (JsonParameterInfo parameterInfo in typeInfo.ParameterCache)
 058            {
 059                arguments[parameterInfo.Position] = parameterInfo.EffectiveDefaultValue;
 060            }
 61
 062            state.Current.CtorArgumentState!.Arguments = arguments;
 063        }
 64    }
 65}
 66