< Summary

Information
Class: System.Text.Json.Serialization.Converters.ImmutableDictionaryOfTKeyTValueConverter<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\ImmutableDictionaryOfTKeyTValueConverter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 24
Coverable lines: 24
Total lines: 49
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
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(TKey,TValue& modreq(...)0%440%
CreateCollection(...)100%110%
ConvertCollection(...)100%110%

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\ImmutableDictionaryOfTKeyTValueConverter.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 ImmutableDictionaryOfTKeyTValueConverter<TDictionary, TKey, TValue>
 11        : DictionaryDefaultConverter<TDictionary, TKey, TValue>
 12        where TDictionary : IReadOnlyDictionary<TKey, TValue>
 13        where TKey : notnull
 14    {
 15        protected sealed override void Add(TKey key, in TValue value, JsonSerializerOptions options, ref ReadStack state
 016        {
 017            Dictionary<TKey, TValue> dictionary = (Dictionary<TKey, TValue>)state.Current.ReturnValue!;
 18
 019            if (options.AllowDuplicateProperties)
 020            {
 021                dictionary[key] = value;
 022            }
 23            else
 024            {
 025                if (!dictionary.TryAdd(key, value))
 026                {
 027                    ThrowHelper.ThrowJsonException_DuplicatePropertyNotAllowed();
 28                }
 029            }
 030        }
 31
 032        internal sealed override bool CanHaveMetadata => false;
 33
 034        internal override bool SupportsCreateObjectDelegate => false;
 35        protected sealed override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state)
 036        {
 037            state.Current.ReturnValue = new Dictionary<TKey, TValue>();
 038        }
 39
 040        internal sealed override bool IsConvertibleCollection => true;
 41        protected sealed override void ConvertCollection(ref ReadStack state, JsonSerializerOptions options)
 042        {
 043            Func<IEnumerable<KeyValuePair<TKey, TValue>>, TDictionary>? creator =
 044                (Func<IEnumerable<KeyValuePair<TKey, TValue>>, TDictionary>?)state.Current.JsonTypeInfo.CreateObjectWith
 045            Debug.Assert(creator != null);
 046            state.Current.ReturnValue = creator((Dictionary<TKey, TValue>)state.Current.ReturnValue!);
 047        }
 48    }
 49}