< Summary

Information
Line coverage
33%
Covered lines: 5
Uncovered lines: 10
Coverable lines: 15
Total lines: 37
Line coverage: 33.3%
Branch coverage
25%
Covered branches: 2
Total branches: 8
Branch coverage: 25%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
CanConvert(...)33.33%6671.42%
CreateConverter(...)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\MemoryConverterFactory.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.Diagnostics;
 5using System.Diagnostics.CodeAnalysis;
 6using System.Reflection;
 7
 8namespace System.Text.Json.Serialization.Converters
 9{
 10    [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)]
 11    internal sealed class MemoryConverterFactory : JsonConverterFactory
 12    {
 13        public override bool CanConvert(Type typeToConvert)
 230114        {
 230115            if (!typeToConvert.IsGenericType || !typeToConvert.IsValueType)
 230116            {
 230117                return false;
 18            }
 19
 020            Type typeDef = typeToConvert.GetGenericTypeDefinition();
 021            return typeDef == typeof(Memory<>) || typeDef == typeof(ReadOnlyMemory<>);
 230122        }
 23
 24        public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options)
 025        {
 026            Debug.Assert(CanConvert(typeToConvert));
 27
 028            Type converterType = typeToConvert.GetGenericTypeDefinition() == typeof(Memory<>) ?
 029                typeof(MemoryConverter<>) : typeof(ReadOnlyMemoryConverter<>);
 30
 031            Type elementType = typeToConvert.GetGenericArguments()[0];
 32
 033            return (JsonConverter)Activator.CreateInstance(
 034                converterType.MakeGenericType(elementType))!;
 035        }
 36    }
 37}