< Summary

Line coverage
30%
Covered lines: 3
Uncovered lines: 7
Coverable lines: 10
Total lines: 36
Line coverage: 30%
Branch coverage
0%
Covered branches: 0
Total branches: 2
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%11100%
CanConvert(...)100%11100%
CreateConverter(...)0%220%
GetAsyncEnumerableInterface(...)100%11100%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableConverterFactory.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.Reflection;
 8using System.Text.Json.Serialization.Converters;
 9
 10namespace System.Text.Json.Serialization
 11{
 12    /// <summary>
 13    /// Converter for streaming <see cref="IAsyncEnumerable{T}" /> values.
 14    /// </summary>
 15    [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)]
 16    internal sealed class IAsyncEnumerableConverterFactory : JsonConverterFactory
 17    {
 318        public IAsyncEnumerableConverterFactory() { }
 19
 96520        public override bool CanConvert(Type typeToConvert) => GetAsyncEnumerableInterface(typeToConvert) is not null;
 21
 22        public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
 023        {
 024            Type? asyncEnumerableInterface = GetAsyncEnumerableInterface(typeToConvert);
 025            Debug.Assert(asyncEnumerableInterface is not null, $"{typeToConvert} not supported by converter.");
 26
 027            Type elementType = asyncEnumerableInterface.GetGenericArguments()[0];
 028            Type converterType = typeof(IAsyncEnumerableOfTConverter<,>).MakeGenericType(typeToConvert, elementType);
 029            return (JsonConverter)Activator.CreateInstance(converterType)!;
 030        }
 31
 32        private static Type? GetAsyncEnumerableInterface(Type type)
 96533            => type.GetCompatibleGenericInterface(typeof(IAsyncEnumerable<>));
 34    }
 35}
 36