| | | 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 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Collections.Concurrent; |
| | | 6 | | using System.Collections.Generic; |
| | | 7 | | using System.Reflection; |
| | | 8 | | using CoreWCF.Description; |
| | | 9 | | |
| | | 10 | | namespace CoreWCF.Channels |
| | | 11 | | { |
| | | 12 | | public class ServiceChannelFactory |
| | | 13 | | { |
| | | 14 | | private delegate object CreateProxyDelegate(MessageDirection direction, ServiceChannel serviceChannel); |
| | 1 | 15 | | private static readonly IDictionary<Type, CreateProxyDelegate> s_createProxyDelegateCache = new ConcurrentDictio |
| | | 16 | | |
| | | 17 | | internal static object CreateProxy(Type interfaceType, Type proxiedType, MessageDirection direction, ServiceChan |
| | | 18 | | { |
| | 1 | 19 | | if (!proxiedType.GetTypeInfo().IsInterface) |
| | | 20 | | { |
| | 0 | 21 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxChannelFac |
| | | 22 | | } |
| | | 23 | | |
| | 1 | 24 | | if (!s_createProxyDelegateCache.TryGetValue(proxiedType, out CreateProxyDelegate createProxyDelegate)) |
| | | 25 | | { |
| | 1 | 26 | | MethodInfo method = typeof(ServiceChannelFactory).GetMethod(nameof(CreateProxyWithType), |
| | 1 | 27 | | BindingFlags.NonPublic | BindingFlags.Static); |
| | 1 | 28 | | MethodInfo generic = method.MakeGenericMethod(proxiedType); |
| | 1 | 29 | | createProxyDelegate = (CreateProxyDelegate)generic.CreateDelegate(typeof(CreateProxyDelegate)); |
| | 1 | 30 | | s_createProxyDelegateCache[proxiedType] = createProxyDelegate; |
| | | 31 | | } |
| | | 32 | | |
| | 1 | 33 | | return createProxyDelegate(direction, serviceChannel); |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | internal static object CreateProxyWithType<TChannel>(MessageDirection direction, ServiceChannel serviceChannel) |
| | | 37 | | { |
| | 1 | 38 | | if (!typeof(TChannel).GetTypeInfo().IsInterface) |
| | | 39 | | { |
| | 0 | 40 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxChannelFac |
| | | 41 | | } |
| | | 42 | | |
| | | 43 | | #pragma warning disable CS0618 // Type or member is obsolete |
| | 1 | 44 | | 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 |
| | 2 | 51 | | if (transparentProxy is ServiceChannelProxy proxy) |
| | | 52 | | { |
| | 2 | 53 | | return proxy.GetServiceChannel(); |
| | | 54 | | } |
| | | 55 | | else |
| | | 56 | | { |
| | 0 | 57 | | return null; |
| | | 58 | | } |
| | | 59 | | #pragma warning restore CS0618 // Type or member is obsolete |
| | | 60 | | } |
| | | 61 | | } |
| | | 62 | | } |