Expression.Call 方法

定义

创建一个 MethodCallExpression

重载

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

创建一个 MethodCallExpression,它表示对使用五个参数的静态方法的调用。

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

创建一个 MethodCallExpression,它表示对使用三个参数的方法的调用。

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

通过调用合适的工厂方法,创建一个 MethodCallExpression,它表示对 static(在 Visual Basic 中为 Shared)方法的调用。

Call(MethodInfo, Expression, Expression, Expression)

创建一个 MethodCallExpression,它表示对使用三个参数的静态方法的调用。

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

通过调用合适的工厂方法,创建一个 MethodCallExpression,它表示方法调用。

Call(Expression, MethodInfo, Expression, Expression)

创建一个 MethodCallExpression,它表示对采用两个参数的方法的调用。

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

创建一个 MethodCallExpression,它表示对使用四个参数的静态方法的调用。

Call(Expression, MethodInfo, Expression[])

创建一个表示调用带参数的方法的 MethodCallExpression

Call(Expression, MethodInfo, IEnumerable<Expression>)

创建一个表示调用带参数的方法的 MethodCallExpression

Call(MethodInfo, Expression[])

创建一个 MethodCallExpression,它表示调用有参数的 static(在 Visual Basic 中为 Shared)方法。

Call(MethodInfo, Expression)

创建一个 MethodCallExpression,它表示对使用一个参数的 static 方法(在 Visual Basic 中为 Shared 方法)的调用。

Call(MethodInfo, IEnumerable<Expression>)

创建一个 MethodCallExpression,它表示对 static 方法(在 Visual Basic 中为 Shared 方法)的调用。

Call(Expression, MethodInfo)

创建一个 MethodCallExpression,它表示调用不带参数的方法。

Call(MethodInfo, Expression, Expression)

创建一个 MethodCallExpression,它表示对使用两个参数的静态方法的调用。

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

创建一个 MethodCallExpression,它表示对使用五个参数的静态方法的调用。

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

参数

method
MethodInfo

要将 MethodInfo 属性设置为与其相等的 Method

arg0
Expression

用于表示第一个参数的 Expression

arg1
Expression

用于表示第二个参数的 Expression

arg2
Expression

用于表示第三个参数的 Expression

arg3
Expression

用于表示第四个参数的 Expression

arg4
Expression

用于表示第五个参数的 Expression

返回

MethodCallExpression

一个 MethodCallExpression,其 NodeType 属性等于 Call,并且其 ObjectMethod 属性设置为指定值。

例外

method 为 null。

适用于

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

创建一个 MethodCallExpression,它表示对使用三个参数的方法的调用。

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

参数

instance
Expression

指定一个实例调用的实例的 Expression。 (对于 static 方法(在 Visual Basic 中为 Shared 方法)应传递 null)。

method
MethodInfo

表示目标方法的 MethodInfo

arg0
Expression

用于表示第一个参数的 Expression

arg1
Expression

用于表示第二个参数的 Expression

arg2
Expression

用于表示第三个参数的 Expression

返回

MethodCallExpression

一个 MethodCallExpression,其 NodeType 属性等于 Call,并且其 ObjectMethod 属性设置为指定值。

适用于

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

通过调用合适的工厂方法,创建一个 MethodCallExpression,它表示对 static(在 Visual Basic 中为 Shared)方法的调用。

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

参数

type
Type

包含指定的 static(在 Visual Basic 中为 Shared)方法的类型。

methodName
String

方法的名称。

typeArguments
Type[]

指定泛型方法的类型参数的 Type 对象的数组。 当 methodName 指定非泛型方法时,此自变量应为 null。

arguments
Expression[]

Expression 对象的数组,表示方法的自变量。

返回

MethodCallExpression

MethodCallExpressionNodeType 属性等于 CallMethod 属性设置为表示指定的 MethodInfo(在 Visual Basic 中为 static)方法的 Shared,并且 Arguments 属性设置为指定自变量。

例外

typemethodNamenull

methodName 或其基类型中找不到这样的方法:名称为 typeArguments、类型参数与 arguments 相匹配,且参数类型与 type 相匹配。

  • 或 - 在 methodName 或其基类型中找到多个这样的方法:名称为 typeArguments,类型参数与 arguments 相匹配,参数类型与 type 相匹配。

注解

Type生成的MethodCallExpression属性等于由 methodName 表示的方法的返回类型。 Object 属性为 null

适用于

Call(MethodInfo, Expression, Expression, Expression)

创建一个 MethodCallExpression,它表示对使用三个参数的静态方法的调用。

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

参数

method
MethodInfo

要将 MethodInfo 属性设置为与其相等的 Method

arg0
Expression

用于表示第一个参数的 Expression

arg1
Expression

用于表示第二个参数的 Expression

arg2
Expression

用于表示第三个参数的 Expression

返回

MethodCallExpression

一个 MethodCallExpression,其 NodeType 属性等于 Call,并且其 ObjectMethod 属性设置为指定值。

例外

method 为 null。

适用于

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

通过调用合适的工厂方法,创建一个 MethodCallExpression,它表示方法调用。

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

参数

instance
Expression

将搜索 ExpressionType 属性值,查看其是否有特定方法。

methodName
String

方法的名称。

typeArguments
Type[]

指定泛型方法的类型参数的 Type 对象的数组。 当 methodName 指定非泛型方法时,此自变量应为 null。

arguments
Expression[]

Expression 对象的数组,表示方法的自变量。

返回

MethodCallExpression

MethodCallExpressionNodeType 属性等于 CallObject 属性等于 instanceMethod 设置为表示指定实例方法的 MethodInfoArguments 设置为指定自变量。

例外

instancemethodNamenull

methodName.Type 或其基类型中找不到这样的方法:名称为 typeArguments、类型参数与 arguments 相匹配,且参数类型与 instance 相匹配。

  • 或 - 在 methodName.Type 或其基类型中找到多个这样的方法:名称为 typeArguments,类型参数与 arguments 相匹配,参数类型与 instance 相匹配。

注解

Type生成的MethodCallExpression属性等于由 methodName 表示的方法的返回类型。

适用于

Call(Expression, MethodInfo, Expression, Expression)

创建一个 MethodCallExpression,它表示对采用两个参数的方法的调用。

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

参数

instance
Expression

指定一个实例调用的实例的 Expression。 (对于 static 方法(在 Visual Basic 中为 Shared 方法)应传递 null)。

method
MethodInfo

表示目标方法的 MethodInfo

arg0
Expression

用于表示第一个参数的 Expression

arg1
Expression

用于表示第二个参数的 Expression

返回

MethodCallExpression

一个 MethodCallExpression,其 NodeType 属性等于 Call,并且其 ObjectMethod 属性设置为指定值。

示例

下面的代码示例演示如何创建调用具有两个参数的实例方法的表达式。

// 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

适用于

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

创建一个 MethodCallExpression,它表示对使用四个参数的静态方法的调用。

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

参数

method
MethodInfo

要将 MethodInfo 属性设置为与其相等的 Method

arg0
Expression

用于表示第一个参数的 Expression

arg1
Expression

用于表示第二个参数的 Expression

arg2
Expression

用于表示第三个参数的 Expression

arg3
Expression

用于表示第四个参数的 Expression

返回

MethodCallExpression

一个 MethodCallExpression,其 NodeType 属性等于 Call,并且其 ObjectMethod 属性设置为指定值。

例外

method 为 null。

适用于

Call(Expression, MethodInfo, Expression[])

创建一个表示调用带参数的方法的 MethodCallExpression

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

参数

instance
Expression

一个 Expression,它指定一个实例方法调用,对于 null 方法(在 Visual Basic 中为 static 方法)应传递 Shared

method
MethodInfo

要将 MethodInfo 属性设置为与其相等的 Method

arguments
Expression[]

用于填充 Expression 集合的 Arguments 对象的数组。

返回

MethodCallExpression

一个 MethodCallExpression,其 NodeType 属性等于 Call,并且其 ObjectMethodArguments 属性设置为指定值。

例外

methodnull

  • 或 - instancenull,且 method 表示一种实例方法。

  • 或 - arguments 不是 null,其中一个或多个元素是 null

instance.Type 不可分配给由 method 表示的方法声明类型。

  • 或 - arguments 中的元素数量与 method 表示的方法的参数数量不相等。

  • 或 - 无法将 arguments 的一个或多个元素分配给由 method 表示的方法的相应参数。

注解

若要表示对 Visual Basic) 方法中 (的调用static,在调用此方法或改为调用Call时传入null``instance参数。Shared

如果 method 表示实例方法, Type 则必须将属性 instance 分配给由 method其表示的方法的声明类型。

null如果没有arguments,它必须具有与方法method所表示的参数数相同的元素数。 每个arguments元素不得null且必须分配给 引用后可能 对应的参数method

备注

仅当相应的方法参数的类型为时 Expression,才会引用元素。 引用表示元素包装在节点中 Quote 。 生成的节点是 UnaryExpressionOperand 属性为元素的 arguments节点。

Arguments生成的MethodCallExpression属性为空(如果argumentsnull)。 否则,它包含与其中一些元素相同的元素 arguments,其中一些元素可能被引用。

Type生成的MethodCallExpression属性等于由 method 表示的方法的返回类型。

适用于

Call(Expression, MethodInfo, IEnumerable<Expression>)

创建一个表示调用带参数的方法的 MethodCallExpression

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

参数

instance
Expression

要将 Expression 属性设置为与其相等的 Object,它为 null(在 Visual Basic 中则为static)方法传递 Shared

method
MethodInfo

要将 MethodInfo 属性设置为与其相等的 Method

arguments
IEnumerable<Expression>

一个 IEnumerable<T>,包含用来填充 Expression 集合的 Arguments 对象。

返回

MethodCallExpression

一个 MethodCallExpression,其 NodeType 属性等于 Call,并且其 ObjectMethodArguments 属性设置为指定值。

例外

methodnull

  • 或 - instancenull,且 method 表示一种实例方法。

instance.Type 不可分配给由 method 表示的方法声明类型。

  • 或 - arguments 中的元素数量与 method 表示的方法的参数数量不相等。

  • 或 - 无法将 arguments 的一个或多个元素分配给由 method 表示的方法的相应参数。

注解

若要表示对 Visual Basic) 方法中 (的调用static,在调用此方法或改为调用Call时传入null``instance参数。Shared

如果 method 表示实例方法, Type 则必须将属性 instance 分配给由 method其表示的方法的声明类型。

null如果没有arguments,它必须具有与方法method所表示的参数数相同的元素数。 每个arguments元素不得null且必须分配给 引用后可能 对应的参数method

备注

仅当相应的方法参数的类型为时 Expression,才会引用元素。 引用表示元素包装在节点中 Quote 。 生成的节点是 UnaryExpressionOperand 属性为元素的 arguments节点。

Arguments生成的MethodCallExpression属性为空(如果argumentsnull)。 否则,它包含与其中一些元素相同的元素 arguments,其中一些元素可能被引用。

Type生成的MethodCallExpression属性等于由 method 表示的方法的返回类型。

适用于

Call(MethodInfo, Expression[])

创建一个 MethodCallExpression,它表示调用有参数的 static(在 Visual Basic 中为 Shared)方法。

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

参数

method
MethodInfo

MethodInfo 表示 static(在 Visual Basic 中为 Shared)方法,以将 Method 属性设置为与其相等。

arguments
Expression[]

用于填充 Expression 集合的 Arguments 对象的数组。

返回

MethodCallExpression

一个 MethodCallExpression,其 NodeType 属性等于 Call,并且其 MethodArguments 属性设置为指定值。

例外

methodnull

arguments 中的元素数量与 method 表示的方法的参数数量不相等。

  • 或 - 无法将 arguments 的一个或多个元素分配给由 method 表示的方法的相应参数。

注解

null如果没有arguments,它必须具有与方法method所表示的参数数相同的元素数。 每个arguments元素不得null且必须分配给 引用后可能 对应的参数method

备注

仅当相应的方法参数的类型为时 Expression,才会引用元素。 引用表示元素包装在节点中 Quote 。 生成的节点是 UnaryExpressionOperand 属性为元素的 arguments节点。

Arguments生成的MethodCallExpression属性为空(如果argumentsnull)。 否则,它包含与其中一些元素相同的元素 arguments,其中一些元素可能被引用。

Type生成的MethodCallExpression属性等于由 method 表示的方法的返回类型。 Object 属性为 null

适用于

Call(MethodInfo, Expression)

创建一个 MethodCallExpression,它表示对使用一个参数的 static 方法(在 Visual Basic 中为 Shared 方法)的调用。

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

参数

method
MethodInfo

要将 MethodInfo 属性设置为与其相等的 Method

arg0
Expression

用于表示第一个参数的 Expression

返回

MethodCallExpression

一个 MethodCallExpression,其 NodeType 属性等于 Call,并且其 ObjectMethod 属性设置为指定值。

例外

method 为 null。

示例

以下示例演示如何创建一个表达式,该表达式在采用一个参数的 Visual Basic) 方法中调用static (Shared

// 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

适用于

Call(MethodInfo, IEnumerable<Expression>)

创建一个 MethodCallExpression,它表示对 static 方法(在 Visual Basic 中为 Shared 方法)的调用。

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

参数

method
MethodInfo

表示目标方法的 MethodInfo

arguments
IEnumerable<Expression>

表示调用参数的 Expression 的集合。

返回

MethodCallExpression

一个 MethodCallExpression,其 NodeType 属性等于 Call,并且其 ObjectMethod 属性设置为指定值。

适用于

Call(Expression, MethodInfo)

创建一个 MethodCallExpression,它表示调用不带参数的方法。

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

参数

instance
Expression

一个 Expression,它指定一个实例方法调用,对于 null 方法(在 Visual Basic 中为 static 方法)应传递 Shared

method
MethodInfo

要将 MethodInfo 属性设置为与其相等的 Method

返回

MethodCallExpression

一个 MethodCallExpression,其 NodeType 属性等于 Call,并且其 ObjectMethod 属性设置为指定值。

例外

methodnull

  • 或 - instancenull,且 method 表示一种实例方法。

instance.Type 不可分配给由 method 表示的方法声明类型。

示例

下面的代码示例演示如何创建调用不带参数的方法的表达式。

// 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

注解

若要表示对 Visual Basic) 方法中 (Shared的调用static,在调用此方法时为null``instance参数传入。

如果 method 表示实例方法, Type 则必须将属性 instance 分配给由 method其表示的方法的声明类型。

Arguments生成的MethodCallExpression属性为空。 该 Type 属性等于由 method表示的方法的返回类型。

适用于

Call(MethodInfo, Expression, Expression)

创建一个 MethodCallExpression,它表示对使用两个参数的静态方法的调用。

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

参数

method
MethodInfo

要将 MethodInfo 属性设置为与其相等的 Method

arg0
Expression

用于表示第一个参数的 Expression

arg1
Expression

用于表示第二个参数的 Expression

返回

MethodCallExpression

一个 MethodCallExpression,其 NodeType 属性等于 Call,并且其 ObjectMethod 属性设置为指定值。

例外

method 为 null。

适用于