< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 15
Coverable lines: 15
Total lines: 38
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
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(...)100%110%
ConvertCollection(...)100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableEnumerableOfTConverter.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    internal class ImmutableEnumerableOfTConverter<TCollection, TElement>
 11        : IEnumerableDefaultConverter<TCollection, TElement>
 12        where TCollection : IEnumerable<TElement>
 13    {
 14        protected sealed override void Add(in TElement value, ref ReadStack state)
 015        {
 016            ((List<TElement>)state.Current.ReturnValue!).Add(value);
 017        }
 18
 019        internal sealed override bool CanHaveMetadata => false;
 20
 021        internal override bool SupportsCreateObjectDelegate => false;
 22        protected sealed override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSeria
 023        {
 024            state.Current.ReturnValue = new List<TElement>();
 025        }
 26
 027        internal sealed override bool IsConvertibleCollection => true;
 28        protected sealed override void ConvertCollection(ref ReadStack state, JsonSerializerOptions options)
 029        {
 030            JsonTypeInfo typeInfo = state.Current.JsonTypeInfo;
 31
 032            Func<IEnumerable<TElement>, TCollection>? creator = (Func<IEnumerable<TElement>, TCollection>?)typeInfo.Crea
 033            Debug.Assert(creator is not null);
 034            state.Current.ReturnValue = creator((List<TElement>)state.Current.ReturnValue!);
 035        }
 36    }
 37}
 38