public Delegate Method(MethodInfo method, Type delegateType)
        {
            var map       = DelegateMap.Method(delegateType, method);
            var declaring = method.DeclaringType;

            // avoid stupid issue in .Net framework... with no CreateDelegate for Generic Interface methods
            if (declaring == null || !(declaring.IsInterface && method.IsGenericMethod))
            {
                // if exact match
                if (map.RetValMap.Matches && Array.TrueForAll(map.ParametersMap, x => x.Matches))
                {
                    return(Delegate.CreateDelegate(delegateType, method));
                }
            }
            // TODO: Simple Delegate.CreateDelegate
            return(BuildDelegate(map,
                                 il => il.EmitMethodCall(method)));
        }
Exemple #2
0
        public Delegate Method(MethodInfo method, Type delegateType)
        {
            return(BuildDelegate(DelegateMap.Method(delegateType, method), parameters =>
            {
                Expression instance;
                IEnumerable <Expression> invokeParams;
                if (method.IsStatic)
                {
                    instance = null;
                    invokeParams = parameters;
                }
                else
                {
                    instance = parameters[0];
                    invokeParams = parameters.Skip(1);
                }

                return Expression.Call(instance, method, invokeParams);
            }));
        }