private static MethodCallExpression CreateMethodCallExpression(MethodInfo method, ParameterExpression instanceParameter, ParameterExpression argumentsParameter) { var call = Expression.Call ( Expression.Convert(instanceParameter, method.DeclaringType), method, MethodInfoExtensions.CreateParameterExpressions ( method, argumentsParameter ) ); return(call); }
/// <summary> /// Creates a late bound fast delegate using lambda expression for a method /// with a 'void' return type. /// </summary> /// <param name="method">The method to create the fast delegate for.</param> /// <returns>A reference to the created fast delegate.</returns> public static LateBoundVoidMethod CreateVoidDelegate(this MethodInfo method) { var instanceParameter = Expression.Parameter(typeof(object), "target"); var argumentsParameter = Expression.Parameter(typeof(object[]), "arguments"); var call = MethodInfoExtensions.CreateMethodCallExpression ( method, instanceParameter, argumentsParameter ); var lambda = Expression.Lambda <LateBoundVoidMethod> ( call, instanceParameter, argumentsParameter ); return(lambda.Compile()); }