< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 15
Coverable lines: 15
Total lines: 38
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
CanConvert(...)0%660%
CreateConverter(...)0%220%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/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)
 014        {
 015            if (!typeToConvert.IsGenericType || !typeToConvert.IsValueType)
 016            {
 017                return false;
 18            }
 19
 020            Type typeDef = typeToConvert.GetGenericTypeDefinition();
 021            return typeDef == typeof(Memory<>) || typeDef == typeof(ReadOnlyMemory<>);
 022        }
 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}
 38