System.Linq.Expressions.Expression.Call C# (CSharp) Method

Call() public static method

Creates a MethodCallExpression that represents a call to an instance method by calling the appropriate factory method.
/// or is null. No method whose name is , whose type parameters match , and whose parameter types match is found in .Type or its base types.-or-More than one method whose name is , whose type parameters match , and whose parameter types match is found in .Type or its base types.
public static Call ( Expression instance, string methodName, Type typeArguments ) : MethodCallExpression
instance Expression An whose property value will be searched for a specific method.
methodName string The name of the method.
typeArguments Type ///An array of objects that specify the type parameters of the generic method. ///This argument should be null when specifies a non-generic method. ///
return MethodCallExpression
        public static MethodCallExpression Call(Expression instance, string methodName, Type[] typeArguments, params Expression[] arguments)
        {
            ContractUtils.RequiresNotNull(instance, nameof(instance));
            ContractUtils.RequiresNotNull(methodName, nameof(methodName));
            if (arguments == null)
            {
                arguments = Array.Empty<Expression>();
            }

            BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
            return Expression.Call(instance, FindMethod(instance.Type, methodName, typeArguments, arguments, flags), arguments);
        }

Same methods

Expression::Call ( Expression instance, MethodInfo method ) : MethodCallExpression
Expression::Call ( Expression instance, MethodInfo method, Expression arg0 ) : MethodCallExpression
Expression::Call ( Expression instance, MethodInfo method, Expression arg0, Expression arg1 ) : MethodCallExpression
Expression::Call ( Expression instance, MethodInfo method, Expression arg0, Expression arg1, Expression arg2 ) : MethodCallExpression
Expression::Call ( Expression instance, MethodInfo method, IEnumerable arguments ) : MethodCallExpression
Expression::Call ( MethodInfo method ) : MethodCallExpression
Expression::Call ( MethodInfo method, Expression arg0 ) : MethodCallExpression
Expression::Call ( MethodInfo method, Expression arg0, Expression arg1 ) : MethodCallExpression
Expression::Call ( MethodInfo method, Expression arg0, Expression arg1, Expression arg2 ) : MethodCallExpression
Expression::Call ( MethodInfo method, Expression arg0, Expression arg1, Expression arg2, Expression arg3 ) : MethodCallExpression
Expression::Call ( MethodInfo method, Expression arg0, Expression arg1, Expression arg2, Expression arg3, Expression arg4 ) : MethodCallExpression
Expression::Call ( MethodInfo method, IEnumerable arguments ) : MethodCallExpression
Expression::Call ( Type type, string methodName, Type typeArguments ) : MethodCallExpression

Usage Example

        private static Func <int[], int[]> GenerateCopyExpression()
        {
            var ctor = typeof(int[]).GetConstructor(new[] { typeof(int) });
            var get  = typeof(int[]).GetMethod("Get", new[] { typeof(int) });
            var set  = typeof(int[]).GetMethod("Set", new[] { typeof(int), typeof(int) });

            var p1     = Exp.Parameter(typeof(int[]));
            var v1     = Exp.Variable(typeof(int[]));
            var v2     = Exp.Variable(typeof(int));
            var @break = Exp.Label();

            var block = Exp.Block(
                new[] { v1, v2 },
                Exp.Assign(v1, Exp.New(ctor, Exp.Property(p1, "Length"))),
                Exp.Assign(v2, Exp.Constant(0)),
                Exp.Loop(
                    Exp.IfThenElse(
                        Exp.LessThan(v2, Exp.Property(p1, "Length")),
                        Exp.Block(
                            Exp.Call(v1, set, v2, Exp.Call(p1, get, v2)),
                            Exp.AddAssign(v2, Exp.Constant(1))
                            ),
                        Exp.Break(@break)
                        ),
                    @break),
                v1
                );

            return(Exp.Lambda <Func <int[], int[]> >(block, new ParameterExpression[] { p1 }).Compile());
        }
All Usage Examples Of System.Linq.Expressions.Expression::Call
Expression