< Summary

Information
Class: System.Text.Json.Serialization.Converters.ISetOfTConverter<T1, T2>
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\ISetOfTConverter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 24
Coverable lines: 24
Total lines: 47
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
Add(TElement& modreq(...)0%220%
CreateCollection(...)0%220%
ConfigureJsonTypeInfo(...)0%660%

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\ISetOfTConverter.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 sealed class ISetOfTConverter<TCollection, TElement>
 11        : IEnumerableDefaultConverter<TCollection, TElement>
 12        where TCollection : ISet<TElement>
 13    {
 014        internal override bool CanPopulate => true;
 15
 16        protected override void Add(in TElement value, ref ReadStack state)
 017        {
 018            TCollection collection = (TCollection)state.Current.ReturnValue!;
 019            collection.Add(value);
 020            if (IsValueType)
 021            {
 022                state.Current.ReturnValue = collection;
 023            };
 024        }
 25
 26        protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOp
 027        {
 028            base.CreateCollection(ref reader, ref state, options);
 029            TCollection returnValue = (TCollection)state.Current.ReturnValue!;
 030            if (returnValue.IsReadOnly)
 031            {
 032                state.Current.ReturnValue = null; // clear out for more accurate JsonPath reporting.
 033                ThrowHelper.ThrowNotSupportedException_CannotPopulateCollection(Type, ref reader, ref state);
 34            }
 035        }
 36
 37        internal override void ConfigureJsonTypeInfo(JsonTypeInfo jsonTypeInfo, JsonSerializerOptions options)
 038        {
 39            // Deserialize as HashSet<TElement> for interface types that support it.
 040            if (jsonTypeInfo.CreateObject is null && Type.IsAssignableFrom(typeof(HashSet<TElement>)))
 041            {
 042                Debug.Assert(Type.IsInterface);
 043                jsonTypeInfo.CreateObject = () => new HashSet<TElement>();
 044            }
 045        }
 46    }
 47}