< Summary

Information
Class: System.Text.Json.Serialization.Converters.StackOfTConverter<T1, T2>
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\Collection\StackOfTConverter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 13
Coverable lines: 13
Total lines: 35
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
Add(TElement& modreq(...)100%110%
CreateCollection(...)0%660%

File(s)

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Serialization\Converters\Collection\StackOfTConverter.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.Collections.Generic;
 5using System.Diagnostics.CodeAnalysis;
 6
 7namespace System.Text.Json.Serialization.Converters
 8{
 9    internal sealed class StackOfTConverter<TCollection, TElement>
 10        : IEnumerableDefaultConverter<TCollection, TElement>
 11        where TCollection : Stack<TElement>
 12    {
 013        internal override bool CanPopulate => true;
 14
 15        protected override void Add(in TElement value, ref ReadStack state)
 016        {
 017            ((TCollection)state.Current.ReturnValue!).Push(value);
 018        }
 19
 20        protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOp
 021        {
 022            if (state.ParentProperty?.TryGetPrePopulatedValue(ref state) == true)
 023            {
 024                return;
 25            }
 26
 027            if (state.Current.JsonTypeInfo.CreateObject == null)
 028            {
 029                ThrowHelper.ThrowNotSupportedException_SerializationNotSupported(state.Current.JsonTypeInfo.Type);
 30            }
 31
 032            state.Current.ReturnValue = state.Current.JsonTypeInfo.CreateObject();
 033        }
 34    }
 35}