< Summary

Information
Class: System.Text.Json.Serialization.Converters.IReadOnlyDictionaryOfTKeyTValueConverter<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\IReadOnlyDictionaryOfTKeyTValueConverter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 20
Coverable lines: 20
Total lines: 44
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%110%
Add(TKey,TValue& modreq(...)0%440%
CreateCollection(...)0%220%

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\IReadOnlyDictionaryOfTKeyTValueConverter.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.Text.Json.Serialization.Metadata;
 6
 7namespace System.Text.Json.Serialization.Converters
 8{
 9    internal sealed class IReadOnlyDictionaryOfTKeyTValueConverter<TDictionary, TKey, TValue>
 10        : DictionaryDefaultConverter<TDictionary, TKey, TValue>
 11        where TDictionary : IReadOnlyDictionary<TKey, TValue>
 12        where TKey : notnull
 13    {
 014        private readonly bool _isDeserializable = typeof(TDictionary).IsAssignableFrom(typeof(Dictionary<TKey, TValue>))
 15
 16        protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, ref ReadStack state)
 017        {
 018            Dictionary<TKey, TValue> dictionary = (Dictionary<TKey, TValue>)state.Current.ReturnValue!;
 19
 020            if (options.AllowDuplicateProperties)
 021            {
 022                dictionary[key] = value;
 023            }
 24            else
 025            {
 026                if (!dictionary.TryAdd(key, value))
 027                {
 028                    ThrowHelper.ThrowJsonException_DuplicatePropertyNotAllowed();
 29                }
 030            }
 031        }
 32
 033        internal override bool SupportsCreateObjectDelegate => false;
 34        protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state)
 035        {
 036            if (!_isDeserializable)
 037            {
 038                ThrowHelper.ThrowNotSupportedException_CannotPopulateCollection(Type, ref reader, ref state);
 39            }
 40
 041            state.Current.ReturnValue = new Dictionary<TKey, TValue>();
 042        }
 43    }
 44}