< Summary

Information
Class: System.Text.Json.Serialization.Converters.IListOfTConverter<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\IListOfTConverter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 24
Coverable lines: 24
Total lines: 50
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 10
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(...)0%220%
CreateCollection(...)0%220%
ConfigureJsonTypeInfo(...)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\IListOfTConverter.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;
 6using System.Text.Json.Serialization.Metadata;
 7
 8namespace System.Text.Json.Serialization.Converters
 9{
 10    /// <summary>
 11    /// Converter for <cref>System.Collections.Generic.IList{TElement}</cref>.
 12    /// </summary>
 13    internal sealed class IListOfTConverter<TCollection, TElement>
 14        : IEnumerableDefaultConverter<TCollection, TElement>
 15        where TCollection : IList<TElement>
 16    {
 017        internal override bool CanPopulate => true;
 18
 19        protected override void Add(in TElement value, ref ReadStack state)
 020        {
 021            TCollection collection = (TCollection)state.Current.ReturnValue!;
 022            collection.Add(value);
 023            if (IsValueType)
 024            {
 025                state.Current.ReturnValue = collection;
 026            };
 027        }
 28
 29        protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOp
 030        {
 031            base.CreateCollection(ref reader, ref state, options);
 032            TCollection returnValue = (TCollection)state.Current.ReturnValue!;
 033            if (returnValue.IsReadOnly)
 034            {
 035                state.Current.ReturnValue = null; // clear out for more accurate JsonPath reporting.
 036                ThrowHelper.ThrowNotSupportedException_CannotPopulateCollection(Type, ref reader, ref state);
 37            }
 038        }
 39
 40        internal override void ConfigureJsonTypeInfo(JsonTypeInfo jsonTypeInfo, JsonSerializerOptions options)
 041        {
 42            // Deserialize as List<T> for interface types that support it.
 043            if (jsonTypeInfo.CreateObject is null && Type.IsAssignableFrom(typeof(List<TElement>)))
 044            {
 045                Debug.Assert(Type.IsInterface);
 046                jsonTypeInfo.CreateObject = () => new List<TElement>();
 047            }
 048        }
 49    }
 50}