< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Dispatcher.DispatchOperationRuntimeHelpers
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Dispatcher/DispatchOperationRuntimeHelpers.cs
Line coverage
95%
Covered lines: 65
Uncovered lines: 3
Coverable lines: 68
Total lines: 122
Line coverage: 95.5%
Branch coverage
77%
Covered branches: 14
Total branches: 18
Branch coverage: 77.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
RegisterOperationInvoker(...)100%11100%
GetKey(...)100%11100%
GetParameterString(...)100%66100%
GetParameterFullName(...)70%101082.35%
.cctor()50%22100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Dispatcher/DispatchOperationRuntimeHelpers.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;
 5using System.Collections.Generic;
 6using System.Reflection;
 7using System.Text;
 8using System.Linq;
 9
 10namespace CoreWCF.Dispatcher;
 11
 12public static class DispatchOperationRuntimeHelpers
 13{
 506314    internal static Dictionary<string, IOperationInvoker> OperationInvokers { get; } = new();
 15
 16    public static void RegisterOperationInvoker(string key, IOperationInvoker invoker)
 17    {
 200718        OperationInvokers[key] = invoker;
 200719    }
 20
 21    internal static string GetKey(MethodInfo method)
 22    {
 302623        StringBuilder stringBuilder = new($"{method.DeclaringType.FullName}.{method.Name}(");
 302624        stringBuilder.Append(string.Join(", ", method.GetParameters().Select(GetParameterString)));
 302625        stringBuilder.Replace("+", ".");
 302626        stringBuilder.Append(")");
 302627        var result = stringBuilder.ToString();
 302628        return result;
 29    }
 30
 31    private static string GetParameterString(ParameterInfo p)
 32    {
 252933        StringBuilder sb = new();
 252934        Type parameterType = p.ParameterType;
 252935        if (p.IsOut)
 36        {
 14037            sb.Append("out ");
 14038            parameterType = p.ParameterType.GetElementType();
 39        }
 238940        else if (p.ParameterType.IsByRef)
 41        {
 13942            sb.Append("ref ");
 13943            parameterType = p.ParameterType.GetElementType();
 44        }
 45
 252946        if (p.IsDefined(typeof(ParamArrayAttribute)))
 47        {
 148            sb.Append("params ");
 49        }
 50
 252951        string parameterName = GetParameterFullName(parameterType);
 252952        sb.Append(parameterName);
 252953        return sb.ToString();
 54    }
 55
 56    private static string GetParameterFullName(Type type)
 57    {
 257258        if (type.IsGenericType)
 59        {
 960            StringBuilder sb = new();
 961            sb.Append(type.FullName.Substring(0, type.FullName.IndexOf('`')));
 962            sb.Append("<");
 963            sb.Append(string.Join(", ", type.GetGenericArguments().Select(GetParameterFullName)));
 964            sb.Append(">");
 965            return sb.ToString();
 66        }
 67
 256368        if (type.IsArray)
 69        {
 3070            return GetParameterFullName(type.GetElementType()) + "[]";
 71        }
 72
 73        string result;
 253374        if (s_isDynamicCodeSupported.Value)
 75        {
 253376            result = s_runtimeIntegratedTypesMap.TryGetValue(type.TypeHandle.Value, out result)
 253377                ? result
 253378                : type.FullName;
 79        }
 80        else
 81        {
 082            result = s_integratedTypesMap.TryGetValue(type, out result)
 083                ? result
 084                : type.FullName;
 85        }
 86
 253387        return result;
 88    }
 89
 3090    private static readonly string s_isDynamicCodeSupportedAppContextSwitchKey = "System.Runtime.CompilerServices.Runtim
 91
 3092    private static readonly Lazy<bool> s_isDynamicCodeSupported = new Lazy<bool>(() =>
 3093        // See https://source.dot.net/#System.Private.CoreLib/src/libraries/System.Private.CoreLib/src/System/Runtime/Co
 1094        AppContext.TryGetSwitch(s_isDynamicCodeSupportedAppContextSwitchKey, out bool isDynamicCodeSupported)
 1095            ? isDynamicCodeSupported
 1096            : true
 3097    );
 98
 3099    private static readonly Dictionary<Type, string> s_integratedTypesMap = new()
 30100    {
 30101        { typeof(bool), "bool" },
 30102        { typeof(byte), "byte" },
 30103        { typeof(sbyte), "sbyte" },
 30104        { typeof(char), "char" },
 30105        { typeof(decimal), "decimal" },
 30106        { typeof(double), "double" },
 30107        { typeof(float), "float" },
 30108        { typeof(int), "int" },
 30109        { typeof(uint), "uint" },
 30110        { typeof(nint), "nint" },
 30111        { typeof(nuint), "nuint" },
 30112        { typeof(long), "long" },
 30113        { typeof(ulong), "ulong" },
 30114        { typeof(short), "short" },
 30115        { typeof(ushort), "ushort" },
 30116        { typeof(object), "object" },
 30117        { typeof(string), "string" }
 30118    };
 119
 30120    private static readonly Dictionary<IntPtr, string> s_runtimeIntegratedTypesMap = s_integratedTypesMap
 1050121        .ToDictionary(kvp => kvp.Key.TypeHandle.Value, kvp => kvp.Value);
 122}