< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.ServiceChannelFactory
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/ServiceChannelFactory.cs
Line coverage
81%
Covered lines: 13
Uncovered lines: 3
Coverable lines: 16
Total lines: 62
Line coverage: 81.2%
Branch coverage
62%
Covered branches: 5
Total branches: 8
Branch coverage: 62.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%11100%
CreateProxy(...)75%4488.88%
CreateProxyWithType(...)50%2266.66%
GetServiceChannel(...)50%2266.66%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/ServiceChannelFactory.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.Concurrent;
 6using System.Collections.Generic;
 7using System.Reflection;
 8using CoreWCF.Description;
 9
 10namespace CoreWCF.Channels
 11{
 12    public class ServiceChannelFactory
 13    {
 14        private delegate object CreateProxyDelegate(MessageDirection direction, ServiceChannel serviceChannel);
 115        private static readonly IDictionary<Type, CreateProxyDelegate> s_createProxyDelegateCache = new ConcurrentDictio
 16
 17        internal static object CreateProxy(Type interfaceType, Type proxiedType, MessageDirection direction, ServiceChan
 18        {
 119            if (!proxiedType.GetTypeInfo().IsInterface)
 20            {
 021                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxChannelFac
 22            }
 23
 124            if (!s_createProxyDelegateCache.TryGetValue(proxiedType, out CreateProxyDelegate createProxyDelegate))
 25            {
 126                MethodInfo method = typeof(ServiceChannelFactory).GetMethod(nameof(CreateProxyWithType),
 127                    BindingFlags.NonPublic | BindingFlags.Static);
 128                MethodInfo generic = method.MakeGenericMethod(proxiedType);
 129                createProxyDelegate = (CreateProxyDelegate)generic.CreateDelegate(typeof(CreateProxyDelegate));
 130                s_createProxyDelegateCache[proxiedType] = createProxyDelegate;
 31            }
 32
 133            return createProxyDelegate(direction, serviceChannel);
 34        }
 35
 36        internal static object CreateProxyWithType<TChannel>(MessageDirection direction, ServiceChannel serviceChannel)
 37        {
 138            if (!typeof(TChannel).GetTypeInfo().IsInterface)
 39            {
 040                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxChannelFac
 41            }
 42
 43#pragma warning disable CS0618 // Type or member is obsolete
 144            return ServiceChannelProxy.CreateProxy<TChannel>(direction, serviceChannel);
 45#pragma warning restore CS0618 // Type or member is obsolete
 46        }
 47
 48        internal static ServiceChannel GetServiceChannel(object transparentProxy)
 49        {
 50#pragma warning disable CS0618 // Type or member is obsolete
 251            if (transparentProxy is ServiceChannelProxy proxy)
 52            {
 253                return proxy.GetServiceChannel();
 54            }
 55            else
 56            {
 057                return null;
 58            }
 59#pragma warning restore CS0618 // Type or member is obsolete
 60        }
 61    }
 62}