< Summary

Information
Class: System.Text.Json.Serialization.Converters.LargeObjectWithParameterizedConstructorConverter<T>
Assembly: System.Text.Json
File(s): C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Serialization\Converters\Object\ObjectWithParameterizedConstructorConverter.Large.cs
Line coverage
29%
Covered lines: 9
Uncovered lines: 22
Coverable lines: 31
Total lines: 65
Line coverage: 29%
Branch coverage
14%
Covered branches: 2
Total branches: 14
Branch coverage: 14.2%
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(...)100%22100%

File(s)

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\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 == null && jsonParameterInfo.IgnoreNullTokensOnRead))
 024            {
 025                if (arg == 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 != null);
 039            Debug.Assert(frame.JsonTypeInfo.CreateObjectWithArgs != 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
 853        {
 854            JsonTypeInfo typeInfo = state.Current.JsonTypeInfo;
 55
 856            object?[] arguments = ArrayPool<object>.Shared.Rent(typeInfo.ParameterCache.Length);
 12057            foreach (JsonParameterInfo parameterInfo in typeInfo.ParameterCache)
 4858            {
 4859                arguments[parameterInfo.Position] = parameterInfo.EffectiveDefaultValue;
 4860            }
 61
 862            state.Current.CtorArgumentState!.Arguments = arguments;
 863        }
 64    }
 65}