Exemple #1
0
 static BeginMethodHandler()
 {
     try
     {
         Type          tArg1ByRef = typeof(TArg1).IsByRef ? typeof(TArg1) : typeof(TArg1).MakeByRefType();
         Type          tArg2ByRef = typeof(TArg2).IsByRef ? typeof(TArg2) : typeof(TArg2).MakeByRefType();
         Type          tArg3ByRef = typeof(TArg3).IsByRef ? typeof(TArg3) : typeof(TArg3).MakeByRefType();
         Type          tArg4ByRef = typeof(TArg4).IsByRef ? typeof(TArg4) : typeof(TArg4).MakeByRefType();
         Type          tArg5ByRef = typeof(TArg5).IsByRef ? typeof(TArg5) : typeof(TArg5).MakeByRefType();
         Type          tArg6ByRef = typeof(TArg6).IsByRef ? typeof(TArg6) : typeof(TArg6).MakeByRefType();
         Type          tArg7ByRef = typeof(TArg7).IsByRef ? typeof(TArg7) : typeof(TArg7).MakeByRefType();
         Type          tArg8ByRef = typeof(TArg8).IsByRef ? typeof(TArg8) : typeof(TArg8).MakeByRefType();
         DynamicMethod dynMethod  = IntegrationMapper.CreateBeginMethodDelegate(typeof(TIntegration), typeof(TTarget), new[] { tArg1ByRef, tArg2ByRef, tArg3ByRef, tArg4ByRef, tArg5ByRef, tArg6ByRef, tArg7ByRef, tArg8ByRef });
         if (dynMethod != null)
         {
             _invokeDelegate = (InvokeDelegate)dynMethod.CreateDelegate(typeof(InvokeDelegate));
         }
     }
     catch (Exception ex)
     {
         throw new CallTargetInvokerException(ex);
     }
     finally
     {
         if (_invokeDelegate is null)
         {
             _invokeDelegate = (TTarget instance, ref TArg1 arg1, ref TArg2 arg2, ref TArg3 arg3, ref TArg4 arg4, ref TArg5 arg5, ref TArg6 arg6, ref TArg7 arg7, ref TArg8 arg8) => CallTargetState.GetDefault();
         }
     }
 }
        static EndMethodHandler()
        {
            Type returnType = typeof(TReturn);

            try
            {
                DynamicMethod dynMethod = IntegrationMapper.CreateEndMethodDelegate(typeof(TIntegration), typeof(TTarget), returnType);
                if (dynMethod != null)
                {
                    _invokeDelegate = (InvokeDelegate)dynMethod.CreateDelegate(typeof(InvokeDelegate));
                }
            }
            catch (Exception ex)
            {
                throw new CallTargetInvokerException(ex);
            }

            if (returnType.IsGenericType)
            {
                Type genericReturnType = returnType.GetGenericTypeDefinition();
                if (typeof(Task).IsAssignableFrom(returnType))
                {
                    // The type is a Task<>
                    _continuationGenerator = (ContinuationGenerator <TTarget, TReturn>)Activator.CreateInstance(typeof(TaskContinuationGenerator <, , ,>).MakeGenericType(typeof(TIntegration), typeof(TTarget), returnType, ContinuationsHelper.GetResultType(returnType)));
                }
#if NETCOREAPP3_1 || NET5_0
                else if (genericReturnType == typeof(ValueTask <>))
                {
                    // The type is a ValueTask<>
                    _continuationGenerator = (ContinuationGenerator <TTarget, TReturn>)Activator.CreateInstance(typeof(ValueTaskContinuationGenerator <, , ,>).MakeGenericType(typeof(TIntegration), typeof(TTarget), returnType, ContinuationsHelper.GetResultType(returnType)));
                }
#endif
            }
            else
            {
                if (returnType == typeof(Task))
                {
                    // The type is a Task
                    _continuationGenerator = new TaskContinuationGenerator <TIntegration, TTarget, TReturn>();
                }
#if NETCOREAPP3_1 || NET5_0
                else if (returnType == typeof(ValueTask))
                {
                    // The type is a ValueTask
                    _continuationGenerator = new ValueTaskContinuationGenerator <TIntegration, TTarget, TReturn>();
                }
#endif
            }
        }
 static BeginMethodSlowHandler()
 {
     try
     {
         DynamicMethod dynMethod = IntegrationMapper.CreateSlowBeginMethodDelegate(typeof(TIntegration), typeof(TTarget));
         if (dynMethod != null)
         {
             _invokeDelegate = (InvokeDelegate)dynMethod.CreateDelegate(typeof(InvokeDelegate));
         }
     }
     catch (Exception ex)
     {
         throw new CallTargetInvokerException(ex);
     }
     finally
     {
         if (_invokeDelegate is null)
         {
             _invokeDelegate = (instance, arguments) => CallTargetState.GetDefault();
         }
     }
 }
 static BeginMethodHandler()
 {
     try
     {
         DynamicMethod dynMethod = IntegrationMapper.CreateBeginMethodDelegate(typeof(TIntegration), typeof(TTarget), Array.Empty <Type>());
         if (dynMethod != null)
         {
             _invokeDelegate = (InvokeDelegate)dynMethod.CreateDelegate(typeof(InvokeDelegate));
         }
     }
     catch (Exception ex)
     {
         throw new CallTargetInvokerException(ex);
     }
     finally
     {
         if (_invokeDelegate is null)
         {
             _invokeDelegate = instance => CallTargetState.GetDefault();
         }
     }
 }
 static EndMethodHandler()
 {
     try
     {
         DynamicMethod dynMethod = IntegrationMapper.CreateEndMethodDelegate(typeof(TIntegration), typeof(TTarget));
         if (dynMethod != null)
         {
             _invokeDelegate = (InvokeDelegate)dynMethod.CreateDelegate(typeof(InvokeDelegate));
         }
     }
     catch (Exception ex)
     {
         throw new CallTargetInvokerException(ex);
     }
     finally
     {
         if (_invokeDelegate is null)
         {
             _invokeDelegate = (instance, exception, state) => CallTargetReturn.GetDefault();
         }
     }
 }
 static BeginMethodHandler()
 {
     try
     {
         DynamicMethod dynMethod = IntegrationMapper.CreateBeginMethodDelegate(typeof(TIntegration), typeof(TTarget), new[] { typeof(TArg1), typeof(TArg2), typeof(TArg3), typeof(TArg4), typeof(TArg5), typeof(TArg6) });
         if (dynMethod != null)
         {
             _invokeDelegate = (InvokeDelegate)dynMethod.CreateDelegate(typeof(InvokeDelegate));
         }
     }
     catch (Exception ex)
     {
         throw new CallTargetInvokerException(ex);
     }
     finally
     {
         if (_invokeDelegate is null)
         {
             _invokeDelegate = (instance, arg1, arg2, arg3, arg4, arg5, arg6) => CallTargetState.GetDefault();
         }
     }
 }
Exemple #7
0
 static BeginMethodHandler()
 {
     try
     {
         Type          tArg1ByRef = typeof(TArg1).IsByRef ? typeof(TArg1) : typeof(TArg1).MakeByRefType();
         DynamicMethod dynMethod  = IntegrationMapper.CreateBeginMethodDelegate(typeof(TIntegration), typeof(TTarget), new[] { tArg1ByRef });
         if (dynMethod != null)
         {
             _invokeDelegate = (InvokeDelegate)dynMethod.CreateDelegate(typeof(InvokeDelegate));
         }
     }
     catch (Exception ex)
     {
         throw new CallTargetInvokerException(ex);
     }
     finally
     {
         if (_invokeDelegate is null)
         {
             _invokeDelegate = (TTarget instance, ref TArg1 arg1) => CallTargetState.GetDefault();
         }
     }
 }