< Summary

Information
Class: System.Text.Json.Serialization.Metadata.JsonTypeInfoResolverChain
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\Metadata\JsonTypeInfoResolverChain.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 42
Coverable lines: 42
Total lines: 73
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 18
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%
OnCollectionModifying()100%110%
GetTypeInfo(...)0%440%
AddFlattened(...)0%660%
System.Text.Json.Serialization.Metadata.IBuiltInJsonTypeInfoResolver.IsCompatibleWithOptions(...)0%440%
ToString()0%440%

File(s)

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Serialization\Metadata\JsonTypeInfoResolverChain.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
 4namespace System.Text.Json.Serialization.Metadata
 5{
 6    internal class JsonTypeInfoResolverChain : ConfigurationList<IJsonTypeInfoResolver>, IJsonTypeInfoResolver, IBuiltIn
 7    {
 08        public JsonTypeInfoResolverChain() : base(null) { }
 09        public override bool IsReadOnly => true;
 10        protected override void OnCollectionModifying()
 011            => ThrowHelper.ThrowInvalidOperationException_TypeInfoResolverChainImmutable();
 12
 13        public JsonTypeInfo? GetTypeInfo(Type type, JsonSerializerOptions options)
 014        {
 015            foreach (IJsonTypeInfoResolver resolver in _list)
 016            {
 017                JsonTypeInfo? typeInfo = resolver.GetTypeInfo(type, options);
 018                if (typeInfo != null)
 019                {
 020                    return typeInfo;
 21                }
 022            }
 23
 024            return null;
 025        }
 26
 27        internal void AddFlattened(IJsonTypeInfoResolver? resolver)
 028        {
 029            switch (resolver)
 30            {
 31                case null or EmptyJsonTypeInfoResolver:
 032                    break;
 33
 34                case JsonTypeInfoResolverChain otherChain:
 035                    _list.AddRange(otherChain);
 036                    break;
 37
 38                default:
 039                    _list.Add(resolver);
 040                    break;
 41            }
 042        }
 43
 44        bool IBuiltInJsonTypeInfoResolver.IsCompatibleWithOptions(JsonSerializerOptions options)
 045        {
 046            foreach (IJsonTypeInfoResolver component in _list)
 047            {
 048                if (!component.IsCompatibleWithOptions(options))
 049                {
 050                    return false;
 51                }
 052            }
 53
 054            return true;
 055        }
 56
 57        public override string ToString()
 058        {
 059            var sb = new StringBuilder("[");
 060            foreach (IJsonTypeInfoResolver resolver in _list)
 061            {
 062                sb.Append(resolver);
 063                sb.Append(", ");
 064            }
 65
 066            if (_list.Count > 0)
 067                sb.Length -= 2;
 68
 069            sb.Append(']');
 070            return sb.ToString();
 071        }
 72    }
 73}