< Summary

Information
Class: System.Text.Json.Serialization.Converters.IEnumerableOfTConverter<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\IEnumerableOfTConverter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 11
Coverable lines: 11
Total lines: 34
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

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

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\IEnumerableOfTConverter.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;
 6
 7namespace System.Text.Json.Serialization.Converters
 8{
 9    /// <summary>
 10    /// Converter for <cref>System.Collections.Generic.IEnumerable{TElement}</cref>.
 11    /// </summary>
 12    internal sealed class IEnumerableOfTConverter<TCollection, TElement>
 13        : IEnumerableDefaultConverter<TCollection, TElement>
 14        where TCollection : IEnumerable<TElement>
 15    {
 016        private readonly bool _isDeserializable = typeof(TCollection).IsAssignableFrom(typeof(List<TElement>));
 17
 18        protected override void Add(in TElement value, ref ReadStack state)
 019        {
 020            ((List<TElement>)state.Current.ReturnValue!).Add(value);
 021        }
 22
 023        internal override bool SupportsCreateObjectDelegate => false;
 24        protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOp
 025        {
 026            if (!_isDeserializable)
 027            {
 028                ThrowHelper.ThrowNotSupportedException_CannotPopulateCollection(Type, ref reader, ref state);
 29            }
 30
 031            state.Current.ReturnValue = new List<TElement>();
 032        }
 33    }
 34}