Example #1
0
        public static Delegate CreateDelegateWrapper(MethodInfo wrappedMethod, object owner, Type funcOrActionType, bool isAction)
        {
            var        methodWrapper    = new MethodWrapper(wrappedMethod, owner);
            var        genericArguments = funcOrActionType.GetGenericArguments();
            MethodInfo wrapMethod       = null;

            if (isAction)
            {
                if (genericArguments.Length == 0)
                {
                    wrapMethod = ActionFuncs[0];
                }
                else
                {
                    wrapMethod = ActionFuncs[genericArguments.Length].MakeGenericMethod(genericArguments);
                }
            }
            else
            {
                wrapMethod = WrapFuncs[genericArguments.Length - 1].MakeGenericMethod(genericArguments);
            }
            return(Delegate.CreateDelegate(funcOrActionType, methodWrapper, wrapMethod));
        }