< Summary

Information
Line coverage
0%
Covered lines: 0
Uncovered lines: 38
Coverable lines: 38
Total lines: 73
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
GetDefaultConverterStrategy()100%110%
.ctor(...)100%110%
OnTryRead(...)0%10100%

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\RootLevelListConverter.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    /// A specialized converter implementation used for root-level value
 12    /// streaming in the JsonSerializer.DeserializeAsyncEnumerable methods.
 13    /// </summary>
 14    internal sealed class RootLevelListConverter<T> : JsonResumableConverter<List<T?>>
 15    {
 16        private readonly JsonTypeInfo<T> _elementTypeInfo;
 017        private protected sealed override ConverterStrategy GetDefaultConverterStrategy() => ConverterStrategy.Enumerabl
 018        internal override Type? ElementType => typeof(T);
 19
 020        public RootLevelListConverter(JsonTypeInfo<T> elementTypeInfo)
 021        {
 022            IsRootLevelMultiContentStreamingConverter = true;
 023            _elementTypeInfo = elementTypeInfo;
 024        }
 25
 26        internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, s
 027        {
 028            Debug.Assert(reader.AllowMultipleValues, "Can only be used by readers allowing trailing content.");
 29
 030            JsonConverter<T> elementConverter = _elementTypeInfo.EffectiveConverter;
 031            state.Current.JsonPropertyInfo = _elementTypeInfo.PropertyInfoForTypeInfo;
 032            var results = (List<T?>?)state.Current.ReturnValue;
 33
 034            while (true)
 035            {
 036                if (state.Current.PropertyState < StackFramePropertyState.ReadValue)
 037                {
 038                    if (!reader.TryAdvanceToNextRootLevelValueWithOptionalReadAhead(elementConverter.RequiresReadAhead, 
 039                    {
 040                        if (isAtEndOfStream)
 041                        {
 42                            // No more root-level JSON values in the stream
 43                            // complete the deserialization process.
 044                            value = results;
 045                            return true;
 46                        }
 47
 48                        // New root-level JSON value found, need to read more data.
 049                        value = default;
 050                        return false;
 51                    }
 52
 053                    state.Current.PropertyState = StackFramePropertyState.ReadValue;
 054                }
 55
 56                // Deserialize the next root-level JSON value.
 057                if (!elementConverter.TryRead(ref reader, typeof(T), options, ref state, out T? element, out _))
 058                {
 059                    value = default;
 060                    return false;
 61                }
 62
 063                if (results is null)
 064                {
 065                    state.Current.ReturnValue = results = [];
 066                }
 67
 068                results.Add(element);
 069                state.Current.EndElement();
 070            }
 071        }
 72    }
 73}