< Summary

Information
Class: System.Text.Json.Serialization.Converters.DictionaryDefaultConverter<T1, T2, T3>
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\DictionaryDefaultConverter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 36
Coverable lines: 36
Total lines: 74
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 16
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
OnWriteResume(...)0%16160%

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\DictionaryDefaultConverter.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.Diagnostics.CodeAnalysis;
 7using System.Text.Json.Serialization.Metadata;
 8
 9namespace System.Text.Json.Serialization.Converters
 10{
 11    /// <summary>
 12    /// Default base class implementation of <cref>JsonDictionaryConverter{TCollection}</cref> .
 13    /// </summary>
 14    internal abstract class DictionaryDefaultConverter<TDictionary, TKey, TValue>
 15        : JsonDictionaryConverter<TDictionary, TKey, TValue>
 16        where TDictionary : IEnumerable<KeyValuePair<TKey, TValue>>
 17        where TKey : notnull
 18    {
 019        internal override bool CanHaveMetadata => true;
 20
 21        protected internal override bool OnWriteResume(
 22            Utf8JsonWriter writer,
 23            TDictionary value,
 24            JsonSerializerOptions options,
 25            ref WriteStack state)
 026        {
 27            IEnumerator<KeyValuePair<TKey, TValue>> enumerator;
 028            if (state.Current.CollectionEnumerator == null)
 029            {
 030                enumerator = value.GetEnumerator();
 031                state.Current.CollectionEnumerator = enumerator;
 032                if (!enumerator.MoveNext())
 033                {
 034                    enumerator.Dispose();
 035                    return true;
 36                }
 037            }
 38            else
 039            {
 040                enumerator = (IEnumerator<KeyValuePair<TKey, TValue>>)state.Current.CollectionEnumerator;
 041            }
 42
 043            JsonTypeInfo typeInfo = state.Current.JsonTypeInfo;
 044            _keyConverter ??= GetConverter<TKey>(typeInfo.KeyTypeInfo!);
 045            _valueConverter ??= GetConverter<TValue>(typeInfo.ElementTypeInfo!);
 46
 47            do
 048            {
 049                if (ShouldFlush(ref state, writer))
 050                {
 051                    return false;
 52                }
 53
 054                if (state.Current.PropertyState < StackFramePropertyState.Name)
 055                {
 056                    state.Current.PropertyState = StackFramePropertyState.Name;
 057                    TKey key = enumerator.Current.Key;
 058                    _keyConverter.WriteAsPropertyNameCore(writer, key, options, state.Current.IsWritingExtensionDataProp
 059                }
 60
 061                TValue element = enumerator.Current.Value;
 062                if (!_valueConverter.TryWrite(writer, element, options, ref state))
 063                {
 064                    return false;
 65                }
 66
 067                state.Current.EndDictionaryEntry();
 068            } while (enumerator.MoveNext());
 69
 070            enumerator.Dispose();
 071            return true;
 072        }
 73    }
 74}