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 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();
         }
     }
 }