Upraviť

Zdieľať cez


Expression.Call Method

Definition

Overloads

Call(MethodInfo, Expression, Expression, Expression, Expression, Expression)

Creates a MethodCallExpression that represents a call to a static method that takes five arguments.

Call(Expression, MethodInfo, Expression, Expression, Expression)

Creates a MethodCallExpression that represents a call to a method that takes three arguments.

Call(Type, String, Type[], Expression[])

Creates a MethodCallExpression that represents a call to a static (Shared in Visual Basic) method by calling the appropriate factory method.

Call(MethodInfo, Expression, Expression, Expression)

Creates a MethodCallExpression that represents a call to a static method that takes three arguments.

Call(Expression, String, Type[], Expression[])

Creates a MethodCallExpression that represents a call to a method by calling the appropriate factory method.

Call(Expression, MethodInfo, Expression, Expression)

Creates a MethodCallExpression that represents a call to a method that takes two arguments.

Call(MethodInfo, Expression, Expression, Expression, Expression)

Creates a MethodCallExpression that represents a call to a static method that takes four arguments.

Call(Expression, MethodInfo, Expression[])

Creates a MethodCallExpression that represents a call to a method that takes arguments.

Call(Expression, MethodInfo, IEnumerable<Expression>)

Creates a MethodCallExpression that represents a call to a method that takes arguments.

Call(MethodInfo, Expression[])

Creates a MethodCallExpression that represents a call to a static (Shared in Visual Basic) method that has arguments.

Call(MethodInfo, Expression)

Creates a MethodCallExpression that represents a call to a static (Shared in Visual Basic) method that takes one argument.

Call(MethodInfo, IEnumerable<Expression>)

Creates a MethodCallExpression that represents a call to a static (Shared in Visual Basic) method.

Call(Expression, MethodInfo)

Creates a MethodCallExpression that represents a call to a method that takes no arguments.

Call(MethodInfo, Expression, Expression)

Creates a MethodCallExpression that represents a call to a static method that takes two arguments.

Call(MethodInfo, Expression, Expression, Expression, Expression, Expression)

Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs

Creates a MethodCallExpression that represents a call to a static method that takes five arguments.

public:
 static System::Linq::Expressions::MethodCallExpression ^ Call(System::Reflection::MethodInfo ^ method, System::Linq::Expressions::Expression ^ arg0, System::Linq::Expressions::Expression ^ arg1, System::Linq::Expressions::Expression ^ arg2, System::Linq::Expressions::Expression ^ arg3, System::Linq::Expressions::Expression ^ arg4);
public static System.Linq.Expressions.MethodCallExpression Call (System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1, System.Linq.Expressions.Expression arg2, System.Linq.Expressions.Expression arg3, System.Linq.Expressions.Expression arg4);
static member Call : System.Reflection.MethodInfo * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (method As MethodInfo, arg0 As Expression, arg1 As Expression, arg2 As Expression, arg3 As Expression, arg4 As Expression) As MethodCallExpression

Parameters

method
MethodInfo

A MethodInfo to set the Method property equal to.

arg0
Expression

The Expression that represents the first argument.

arg1
Expression

The Expression that represents the second argument.

arg2
Expression

The Expression that represents the third argument.

arg3
Expression

The Expression that represents the fourth argument.

arg4
Expression

The Expression that represents the fifth argument.

Returns

A MethodCallExpression that has the NodeType property equal to Call and the Object and Method properties set to the specified values.

Exceptions

method is null.

Applies to

Call(Expression, MethodInfo, Expression, Expression, Expression)

Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs

Creates a MethodCallExpression that represents a call to a method that takes three arguments.

public:
 static System::Linq::Expressions::MethodCallExpression ^ Call(System::Linq::Expressions::Expression ^ instance, System::Reflection::MethodInfo ^ method, System::Linq::Expressions::Expression ^ arg0, System::Linq::Expressions::Expression ^ arg1, System::Linq::Expressions::Expression ^ arg2);
public static System.Linq.Expressions.MethodCallExpression Call (System.Linq.Expressions.Expression instance, System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1, System.Linq.Expressions.Expression arg2);
public static System.Linq.Expressions.MethodCallExpression Call (System.Linq.Expressions.Expression? instance, System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1, System.Linq.Expressions.Expression arg2);
static member Call : System.Linq.Expressions.Expression * System.Reflection.MethodInfo * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (instance As Expression, method As MethodInfo, arg0 As Expression, arg1 As Expression, arg2 As Expression) As MethodCallExpression

Parameters

instance
Expression

An Expression that specifies the instance for an instance call. (pass null for a static (Shared in Visual Basic) method).

method
MethodInfo

The MethodInfo that represents the target method.

arg0
Expression

The Expression that represents the first argument.

arg1
Expression

The Expression that represents the second argument.

arg2
Expression

The Expression that represents the third argument.

Returns

A MethodCallExpression that has the NodeType property equal to Call and the Object and Method properties set to the specified values.

Applies to

Call(Type, String, Type[], Expression[])

Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs

Creates a MethodCallExpression that represents a call to a static (Shared in Visual Basic) method by calling the appropriate factory method.

public:
 static System::Linq::Expressions::MethodCallExpression ^ Call(Type ^ type, System::String ^ methodName, cli::array <Type ^> ^ typeArguments, ... cli::array <System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.MethodCallExpression Call (Type type, string methodName, Type[] typeArguments, params System.Linq.Expressions.Expression[] arguments);
public static System.Linq.Expressions.MethodCallExpression Call (Type type, string methodName, Type[]? typeArguments, params System.Linq.Expressions.Expression[]? arguments);
static member Call : Type * string * Type[] * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (type As Type, methodName As String, typeArguments As Type(), ParamArray arguments As Expression()) As MethodCallExpression

Parameters

type
Type

The type that contains the specified static (Shared in Visual Basic) method.

methodName
String

The name of the method.

typeArguments
Type[]

An array of Type objects that specify the type parameters of the generic method. This argument should be null when methodName specifies a non-generic method.

arguments
Expression[]

An array of Expression objects that represent the arguments to the method.

Returns

A MethodCallExpression that has the NodeType property equal to Call, the Method property set to the MethodInfo that represents the specified static (Shared in Visual Basic) method, and the Arguments property set to the specified arguments.

Exceptions

type or methodName is null.

No method whose name is methodName, whose type parameters match typeArguments, and whose parameter types match arguments is found in type or its base types.

-or-

More than one method whose name is methodName, whose type parameters match typeArguments, and whose parameter types match arguments is found in type or its base types.

Remarks

The Type property of the resulting MethodCallExpression is equal to the return type of the method denoted by methodName. The Object property is null.

Applies to

Call(MethodInfo, Expression, Expression, Expression)

Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs

Creates a MethodCallExpression that represents a call to a static method that takes three arguments.

public:
 static System::Linq::Expressions::MethodCallExpression ^ Call(System::Reflection::MethodInfo ^ method, System::Linq::Expressions::Expression ^ arg0, System::Linq::Expressions::Expression ^ arg1, System::Linq::Expressions::Expression ^ arg2);
public static System.Linq.Expressions.MethodCallExpression Call (System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1, System.Linq.Expressions.Expression arg2);
static member Call : System.Reflection.MethodInfo * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (method As MethodInfo, arg0 As Expression, arg1 As Expression, arg2 As Expression) As MethodCallExpression

Parameters

method
MethodInfo

A MethodInfo to set the Method property equal to.

arg0
Expression

The Expression that represents the first argument.

arg1
Expression

The Expression that represents the second argument.

arg2
Expression

The Expression that represents the third argument.

Returns

A MethodCallExpression that has the NodeType property equal to Call and the Object and Method properties set to the specified values.

Exceptions

method is null.

Applies to

Call(Expression, String, Type[], Expression[])

Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs

Creates a MethodCallExpression that represents a call to a method by calling the appropriate factory method.

public:
 static System::Linq::Expressions::MethodCallExpression ^ Call(System::Linq::Expressions::Expression ^ instance, System::String ^ methodName, cli::array <Type ^> ^ typeArguments, ... cli::array <System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.MethodCallExpression Call (System.Linq.Expressions.Expression instance, string methodName, Type[] typeArguments, params System.Linq.Expressions.Expression[] arguments);
public static System.Linq.Expressions.MethodCallExpression Call (System.Linq.Expressions.Expression instance, string methodName, Type[]? typeArguments, params System.Linq.Expressions.Expression[]? arguments);
static member Call : System.Linq.Expressions.Expression * string * Type[] * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (instance As Expression, methodName As String, typeArguments As Type(), ParamArray arguments As Expression()) As MethodCallExpression

Parameters

instance
Expression

An Expression whose Type property value will be searched for a specific method.

methodName
String

The name of the method.

typeArguments
Type[]

An array of Type objects that specify the type parameters of the generic method. This argument should be null when methodName specifies a non-generic method.

arguments
Expression[]

An array of Expression objects that represents the arguments to the method.

Returns

A MethodCallExpression that has the NodeType property equal to Call, the Object property equal to instance, Method set to the MethodInfo that represents the specified instance method, and Arguments set to the specified arguments.

Exceptions

instance or methodName is null.

No method whose name is methodName, whose type parameters match typeArguments, and whose parameter types match arguments is found in instance.Type or its base types.

-or-

More than one method whose name is methodName, whose type parameters match typeArguments, and whose parameter types match arguments is found in instance.Type or its base types.

Remarks

The Type property of the resulting MethodCallExpression is equal to the return type of the method denoted by methodName.

Applies to

Call(Expression, MethodInfo, Expression, Expression)

Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs

Creates a MethodCallExpression that represents a call to a method that takes two arguments.

public:
 static System::Linq::Expressions::MethodCallExpression ^ Call(System::Linq::Expressions::Expression ^ instance, System::Reflection::MethodInfo ^ method, System::Linq::Expressions::Expression ^ arg0, System::Linq::Expressions::Expression ^ arg1);
public static System.Linq.Expressions.MethodCallExpression Call (System.Linq.Expressions.Expression instance, System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1);
public static System.Linq.Expressions.MethodCallExpression Call (System.Linq.Expressions.Expression? instance, System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1);
static member Call : System.Linq.Expressions.Expression * System.Reflection.MethodInfo * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (instance As Expression, method As MethodInfo, arg0 As Expression, arg1 As Expression) As MethodCallExpression

Parameters

instance
Expression

An Expression that specifies the instance for an instance call. (pass null for a static (Shared in Visual Basic) method).

method
MethodInfo

The MethodInfo that represents the target method.

arg0
Expression

The Expression that represents the first argument.

arg1
Expression

The Expression that represents the second argument.

Returns

A MethodCallExpression that has the NodeType property equal to Call and the Object and Method properties set to the specified values.

Examples

The following code example shows how to create an expression that calls an instance method that has two arguments.

// Add the following directive to your file:
// using System.Linq.Expressions;
public class SampleClass
{
    public int AddIntegers(int arg1, int arg2)
    {
        return arg1 + arg2;
    }
}

static public void TestCall()
{
    // This expression represents a call to an instance method that has two arguments.
    // The first argument is an expression that creates a new object of the specified type.
    Expression callExpr = Expression.Call(
        Expression.New(typeof(SampleClass)),
        typeof(SampleClass).GetMethod("AddIntegers", new Type[] { typeof(int), typeof(int) }),
        Expression.Constant(1),
        Expression.Constant(2)
        );

    // Print out the expression.
    Console.WriteLine(callExpr.ToString());

    // The following statement first creates an expression tree,
    // then compiles it, and then executes it.
    Console.WriteLine(Expression.Lambda<Func<int>>(callExpr).Compile()());

    // This code example produces the following output:
    //
    // new SampleClass().AddIntegers(1, 2)
    // 3
}
' Add the following directive to your file:
' Imports System.Linq.Expressions  

Public Class SampleClass
    Public Function AddIntegers(ByVal arg1 As Integer, ByVal arg2 As Integer) As Integer
        Return (arg1 + arg2)
    End Function
End Class
Public Shared Sub TestCall()
    ' This expression represents a call to an instance method that has two arguments.
    ' The first argument is an expression that creates a new object of the specified type.
    Dim callExpr As Expression = Expression.Call(
        Expression.[New](GetType(SampleClass)),
        GetType(SampleClass).GetMethod("AddIntegers", New Type() {GetType(Integer), GetType(Integer)}),
        Expression.Constant(1),
        Expression.Constant(2)
      )

    ' Print the expression.
    Console.WriteLine(callExpr.ToString())

    ' The following statement first creates an expression tree,
    ' then compiles it, and then executes it.
    Console.WriteLine(Expression.Lambda(Of Func(Of Integer))(callExpr).Compile()())
End Sub

' This code example produces the following output:
'
' new SampleClass().AddIntegers(1, 2)
' 3

Applies to

Call(MethodInfo, Expression, Expression, Expression, Expression)

Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs

Creates a MethodCallExpression that represents a call to a static method that takes four arguments.

public:
 static System::Linq::Expressions::MethodCallExpression ^ Call(System::Reflection::MethodInfo ^ method, System::Linq::Expressions::Expression ^ arg0, System::Linq::Expressions::Expression ^ arg1, System::Linq::Expressions::Expression ^ arg2, System::Linq::Expressions::Expression ^ arg3);
public static System.Linq.Expressions.MethodCallExpression Call (System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1, System.Linq.Expressions.Expression arg2, System.Linq.Expressions.Expression arg3);
static member Call : System.Reflection.MethodInfo * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (method As MethodInfo, arg0 As Expression, arg1 As Expression, arg2 As Expression, arg3 As Expression) As MethodCallExpression

Parameters

method
MethodInfo

A MethodInfo to set the Method property equal to.

arg0
Expression

The Expression that represents the first argument.

arg1
Expression

The Expression that represents the second argument.

arg2
Expression

The Expression that represents the third argument.

arg3
Expression

The Expression that represents the fourth argument.

Returns

A MethodCallExpression that has the NodeType property equal to Call and the Object and Method properties set to the specified values.

Exceptions

method is null.

Applies to

Call(Expression, MethodInfo, Expression[])

Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs

Creates a MethodCallExpression that represents a call to a method that takes arguments.

public:
 static System::Linq::Expressions::MethodCallExpression ^ Call(System::Linq::Expressions::Expression ^ instance, System::Reflection::MethodInfo ^ method, ... cli::array <System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.MethodCallExpression Call (System.Linq.Expressions.Expression instance, System.Reflection.MethodInfo method, params System.Linq.Expressions.Expression[] arguments);
public static System.Linq.Expressions.MethodCallExpression Call (System.Linq.Expressions.Expression? instance, System.Reflection.MethodInfo method, params System.Linq.Expressions.Expression[]? arguments);
static member Call : System.Linq.Expressions.Expression * System.Reflection.MethodInfo * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (instance As Expression, method As MethodInfo, ParamArray arguments As Expression()) As MethodCallExpression

Parameters

instance
Expression

An Expression that specifies the instance for an instance method call (pass null for a static (Shared in Visual Basic) method).

method
MethodInfo

A MethodInfo to set the Method property equal to.

arguments
Expression[]

An array of Expression objects to use to populate the Arguments collection.

Returns

A MethodCallExpression that has the NodeType property equal to Call and the Object, Method, and Arguments properties set to the specified values.

Exceptions

method is null.

-or-

instance is null and method represents an instance method.

-or-

arguments is not null and one or more of its elements is null.

instance.Type is not assignable to the declaring type of the method represented by method.

-or-

The number of elements in arguments does not equal the number of parameters for the method represented by method.

-or-

One or more of the elements of arguments is not assignable to the corresponding parameter for the method represented by method.

Remarks

To represent a call to a static (Shared in Visual Basic) method, pass in null for the instance parameter when you call this method, or call Call instead.

If method represents an instance method, the Type property of instance must be assignable to the declaring type of the method represented by method.

If arguments is not null, it must have the same number of elements as the number of parameters for the method represented by method. Each element in arguments must not be null and must be assignable to the corresponding parameter of method, possibly after quoting.

Note

An element will be quoted only if the corresponding method parameter is of type Expression. Quoting means the element is wrapped in a Quote node. The resulting node is a UnaryExpression whose Operand property is the element of arguments.

The Arguments property of the resulting MethodCallExpression is empty if arguments is null. Otherwise, it contains the same elements as arguments, some of which may be quoted.

The Type property of the resulting MethodCallExpression is equal to the return type of the method represented by method.

Applies to

Call(Expression, MethodInfo, IEnumerable<Expression>)

Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs

Creates a MethodCallExpression that represents a call to a method that takes arguments.

public:
 static System::Linq::Expressions::MethodCallExpression ^ Call(System::Linq::Expressions::Expression ^ instance, System::Reflection::MethodInfo ^ method, System::Collections::Generic::IEnumerable<System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.MethodCallExpression Call (System.Linq.Expressions.Expression instance, System.Reflection.MethodInfo method, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> arguments);
public static System.Linq.Expressions.MethodCallExpression Call (System.Linq.Expressions.Expression? instance, System.Reflection.MethodInfo method, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression>? arguments);
static member Call : System.Linq.Expressions.Expression * System.Reflection.MethodInfo * seq<System.Linq.Expressions.Expression> -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (instance As Expression, method As MethodInfo, arguments As IEnumerable(Of Expression)) As MethodCallExpression

Parameters

instance
Expression

An Expression to set the Object property equal to (pass null for a static (Shared in Visual Basic) method).

method
MethodInfo

A MethodInfo to set the Method property equal to.

arguments
IEnumerable<Expression>

An IEnumerable<T> that contains Expression objects to use to populate the Arguments collection.

Returns

A MethodCallExpression that has the NodeType property equal to Call and the Object, Method, and Arguments properties set to the specified values.

Exceptions

method is null.

-or-

instance is null and method represents an instance method.

instance.Type is not assignable to the declaring type of the method represented by method.

-or-

The number of elements in arguments does not equal the number of parameters for the method represented by method.

-or-

One or more of the elements of arguments is not assignable to the corresponding parameter for the method represented by method.

Remarks

To represent a call to a static (Shared in Visual Basic) method, pass in null for the instance parameter when you call this method, or call Call instead.

If method represents an instance method, the Type property of instance must be assignable to the declaring type of the method represented by method.

If arguments is not null, it must have the same number of elements as the number of parameters for the method represented by method. Each element in arguments must not be null and must be assignable to the corresponding parameter of method, possibly after quoting.

Note

An element will be quoted only if the corresponding method parameter is of type Expression. Quoting means the element is wrapped in a Quote node. The resulting node is a UnaryExpression whose Operand property is the element of arguments.

The Arguments property of the resulting MethodCallExpression is empty if arguments is null. Otherwise, it contains the same elements as arguments, some of which may be quoted.

The Type property of the resulting MethodCallExpression is equal to the return type of the method represented by method.

Applies to

Call(MethodInfo, Expression[])

Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs

Creates a MethodCallExpression that represents a call to a static (Shared in Visual Basic) method that has arguments.

public:
 static System::Linq::Expressions::MethodCallExpression ^ Call(System::Reflection::MethodInfo ^ method, ... cli::array <System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.MethodCallExpression Call (System.Reflection.MethodInfo method, params System.Linq.Expressions.Expression[] arguments);
public static System.Linq.Expressions.MethodCallExpression Call (System.Reflection.MethodInfo method, params System.Linq.Expressions.Expression[]? arguments);
static member Call : System.Reflection.MethodInfo * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (method As MethodInfo, ParamArray arguments As Expression()) As MethodCallExpression

Parameters

method
MethodInfo

A MethodInfo that represents a static (Shared in Visual Basic) method to set the Method property equal to.

arguments
Expression[]

An array of Expression objects to use to populate the Arguments collection.

Returns

A MethodCallExpression that has the NodeType property equal to Call and the Method and Arguments properties set to the specified values.

Exceptions

method is null.

The number of elements in arguments does not equal the number of parameters for the method represented by method.

-or-

One or more of the elements of arguments is not assignable to the corresponding parameter for the method represented by method.

Remarks

If arguments is not null, it must have the same number of elements as the number of parameters for the method represented by method. Each element in arguments must not be null and must be assignable to the corresponding parameter of method, possibly after quoting.

Note

An element will be quoted only if the corresponding method parameter is of type Expression. Quoting means the element is wrapped in a Quote node. The resulting node is a UnaryExpression whose Operand property is the element of arguments.

The Arguments property of the resulting MethodCallExpression is empty if arguments is null. Otherwise, it contains the same elements as arguments, some of which may be quoted.

The Type property of the resulting MethodCallExpression is equal to the return type of the method represented by method. The Object property is null.

Applies to

Call(MethodInfo, Expression)

Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs

Creates a MethodCallExpression that represents a call to a static (Shared in Visual Basic) method that takes one argument.

public:
 static System::Linq::Expressions::MethodCallExpression ^ Call(System::Reflection::MethodInfo ^ method, System::Linq::Expressions::Expression ^ arg0);
public static System.Linq.Expressions.MethodCallExpression Call (System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0);
static member Call : System.Reflection.MethodInfo * System.Linq.Expressions.Expression -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (method As MethodInfo, arg0 As Expression) As MethodCallExpression

Parameters

method
MethodInfo

A MethodInfo to set the Method property equal to.

arg0
Expression

The Expression that represents the first argument.

Returns

A MethodCallExpression that has the NodeType property equal to Call and the Object and Method properties set to the specified values.

Exceptions

method is null.

Examples

The following example demonstrates how to create an expression that calls a static (Shared in Visual Basic) method that takes one argument.

// Add the following directive to your file:
// using System.Linq.Expressions;

public class SampleClass
{
    public static int Increment(int arg1)
    {
        return arg1 + 1;
    }
}

static public void TestCall()
{

    //This expression represents a call to an instance method with one argument.
    Expression callExpr = Expression.Call(
                            typeof(SampleClass).GetMethod("Increment"),
                            Expression.Constant(2)
                        );

    // Print out the expression.
    Console.WriteLine(callExpr.ToString());

    // The following statement first creates an expression tree,
    // then compiles it, and then executes it.
    Console.WriteLine(Expression.Lambda<Func<int>>(callExpr).Compile()());

    // This code example produces the following output:
    //
    // Increment(2)
    // 3
}
' Add the following directive to your file:
' Imports System.Linq.Expressions  

Public Class SampleClass
    Shared Function Increment(ByVal arg1 As Integer) As Integer
        Return arg1 + 1
    End Function
End Class
Shared Sub TestCall()
    'This expression represents a call to an instance method with one argument.
    Dim callExpr As Expression = Expression.Call(
        GetType(SampleClass).GetMethod("Increment"),
        Expression.Constant(2))

    ' Print the expression.
    Console.WriteLine(callExpr.ToString())

    ' The following statement first creates an expression tree,
    ' then compiles it, and then executes it.
    Console.WriteLine(Expression.Lambda(Of Func(Of Integer))(callExpr).Compile()())
End Sub

' This code example produces the following output:
'
' Increment(2)
' 3

Applies to

Call(MethodInfo, IEnumerable<Expression>)

Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs

Creates a MethodCallExpression that represents a call to a static (Shared in Visual Basic) method.

public:
 static System::Linq::Expressions::MethodCallExpression ^ Call(System::Reflection::MethodInfo ^ method, System::Collections::Generic::IEnumerable<System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.MethodCallExpression Call (System.Reflection.MethodInfo method, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> arguments);
public static System.Linq.Expressions.MethodCallExpression Call (System.Reflection.MethodInfo method, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression>? arguments);
static member Call : System.Reflection.MethodInfo * seq<System.Linq.Expressions.Expression> -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (method As MethodInfo, arguments As IEnumerable(Of Expression)) As MethodCallExpression

Parameters

method
MethodInfo

The MethodInfo that represents the target method.

arguments
IEnumerable<Expression>

A collection of Expression that represents the call arguments.

Returns

A MethodCallExpression that has the NodeType property equal to Call and the Object and Method properties set to the specified values.

Applies to

Call(Expression, MethodInfo)

Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs

Creates a MethodCallExpression that represents a call to a method that takes no arguments.

public:
 static System::Linq::Expressions::MethodCallExpression ^ Call(System::Linq::Expressions::Expression ^ instance, System::Reflection::MethodInfo ^ method);
public static System.Linq.Expressions.MethodCallExpression Call (System.Linq.Expressions.Expression instance, System.Reflection.MethodInfo method);
public static System.Linq.Expressions.MethodCallExpression Call (System.Linq.Expressions.Expression? instance, System.Reflection.MethodInfo method);
static member Call : System.Linq.Expressions.Expression * System.Reflection.MethodInfo -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (instance As Expression, method As MethodInfo) As MethodCallExpression

Parameters

instance
Expression

An Expression that specifies the instance for an instance method call (pass null for a static (Shared in Visual Basic) method).

method
MethodInfo

A MethodInfo to set the Method property equal to.

Returns

A MethodCallExpression that has the NodeType property equal to Call and the Object and Method properties set to the specified values.

Exceptions

method is null.

-or-

instance is null and method represents an instance method.

instance.Type is not assignable to the declaring type of the method represented by method.

Examples

The following code example shows how to create an expression that calls a method without arguments.

// Add the following directive to your file:
// using System.Linq.Expressions;

// This expression represents a call to an instance method without arguments.
Expression callExpr = Expression.Call(
    Expression.Constant("sample string"), typeof(String).GetMethod("ToUpper", new Type[] { }));

// Print out the expression.
Console.WriteLine(callExpr.ToString());

// The following statement first creates an expression tree,
// then compiles it, and then executes it.
Console.WriteLine(Expression.Lambda<Func<String>>(callExpr).Compile()());

// This code example produces the following output:
//
// "sample string".ToUpper
// SAMPLE STRING
' Add the following directive to your file:
' Imports System.Linq.Expressions   

' This expression represents a call to an instance method without arguments.
Dim callExpr As Expression = Expression.Call(
    Expression.Constant("sample string"), GetType(String).GetMethod("ToUpper", New Type() {}))

' Print the expression.
Console.WriteLine(callExpr.ToString())

' The following statement first creates an expression tree,
' then compiles it, and then executes it.  
Console.WriteLine(Expression.Lambda(Of Func(Of String))(callExpr).Compile()())

' This code example produces the following output:
'
' "sample string".ToUpper
' SAMPLE STRING

Remarks

To represent a call to a static (Shared in Visual Basic) method, pass in null for the instance parameter when you call this method.

If method represents an instance method, the Type property of instance must be assignable to the declaring type of the method represented by method.

The Arguments property of the resulting MethodCallExpression is empty. The Type property is equal to the return type of the method represented by method.

Applies to

Call(MethodInfo, Expression, Expression)

Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs

Creates a MethodCallExpression that represents a call to a static method that takes two arguments.

public:
 static System::Linq::Expressions::MethodCallExpression ^ Call(System::Reflection::MethodInfo ^ method, System::Linq::Expressions::Expression ^ arg0, System::Linq::Expressions::Expression ^ arg1);
public static System.Linq.Expressions.MethodCallExpression Call (System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1);
static member Call : System.Reflection.MethodInfo * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (method As MethodInfo, arg0 As Expression, arg1 As Expression) As MethodCallExpression

Parameters

method
MethodInfo

A MethodInfo to set the Method property equal to.

arg0
Expression

The Expression that represents the first argument.

arg1
Expression

The Expression that represents the second argument.

Returns

A MethodCallExpression that has the NodeType property equal to Call and the Object and Method properties set to the specified values.

Exceptions

method is null.

Applies to