internal static object InvokeFunc <T1, T2, T3, T4, T5, TResult>(Action <T1, T2, T3, T4, T5, TResult> method, RuntimeTypeBinding binding, params object[] methodParameters)
 {
     return(InvokeMethodInternal(method, binding, false, methodParameters));
 }
 internal static void InvokeActionCached <T1, T2, T3, T4, T5>(Action <T1, T2, T3, T4, T5> method, RuntimeTypeBinding binding, params object[] methodParameters)
 {
     InvokeMethodInternal(method, binding, true, methodParameters);
 }
 internal static void InvokeAction <T1, T2, T3>(Action <T1, T2, T3> method, RuntimeTypeBinding binding, params object[] methodParameters)
 {
     InvokeMethodInternal(method, binding, false, methodParameters);
 }
        private static MethodInfo GetGenericMethod(Delegate methodDelegate, bool useCache, RuntimeTypeBinding binding)
        {
            var method = methodDelegate.Method;

            if (!method.IsGenericMethod)
            {
                return(method);
            }

            var genericArguments = method.GetGenericArguments().Select(binding.GetUnderlyingType).ToArray();

            if (!useCache)
            {
                return(MakeGenericMethod(method, genericArguments));
            }

            var        hashCode = CalcHashCode(methodDelegate, genericArguments);
            MethodInfo result;

            if (CachedMethods.TryGetValue(hashCode, out result))
            {
                return(result);
            }

            result = MakeGenericMethod(method, genericArguments);
            CachedMethods.TryAdd(hashCode, result);

            return(result);
        }
        private static object InvokeMethodInternal(Delegate methodDelegate, RuntimeTypeBinding binding, bool useCache, params object[] methodParameters)
        {
            var genericMethod = GetGenericMethod(methodDelegate, useCache, binding);

            return(genericMethod.Invoke(methodDelegate.Target, methodParameters));
        }
 internal static object InvokeFuncCached <T1, T2, T3, TResult>(Func <T1, T2, T3, TResult> method, RuntimeTypeBinding binding, params object[] methodParameters)
 {
     return(InvokeMethodInternal(method, binding, true, methodParameters));
 }