Expression.Call 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
Call(MethodInfo, Expression, Expression, Expression, Expression, Expression)
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
创建一个 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
表示第一个参数的 < a0/>
- arg1
- Expression
表示第二个参数的 < a0/>
- arg2
- Expression
表示第三个参数的 < a0/>
- arg3
- Expression
表示第四个参数的 < a0/>
- arg4
- Expression
表示 Expression 第五个参数。
返回
一个MethodCallExpression属性NodeType等于Call和ObjectMethod属性设置为指定值。
例外
method 为 null。
适用于
Call(Expression, MethodInfo, Expression, Expression, Expression)
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
创建一个 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 指定实例调用的实例。 (为静态方法传递 null(在 Visual Basic 中共享) 方法)。
- method
- MethodInfo
表示 MethodInfo 目标方法的表示。
- arg0
- Expression
表示第一个参数的 < a0/>
- arg1
- Expression
表示第二个参数的 < a0/>
- arg2
- Expression
表示第三个参数的 < a0/>
返回
一个MethodCallExpression属性NodeType等于Call和ObjectMethod属性设置为指定值。
适用于
Call(Type, String, Type[], Expression[])
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
通过调用适当的工厂方法创建一个MethodCallExpression表示对 (Shared在 Visual Basic) 方法的调用static。
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);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Calling a generic method requires dynamic code generation. This can be suppressed if the method is not generic.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calling a generic method cannot be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method. This can be suppressed if the method is not generic.")]
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);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calling a generic method cannot be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method. This can be suppressed if the method is not generic.")]
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
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Calling a generic method requires dynamic code generation. This can be suppressed if the method is not generic.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calling a generic method cannot be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method. This can be suppressed if the method is not generic.")>]
static member Call : Type * string * Type[] * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.MethodCallExpression
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calling a generic method cannot be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method. This can be suppressed if the method is not generic.")>]
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 (Shared 在 Visual Basic 中)方法的类型。
- methodName
- String
方法的名称。
- arguments
- Expression[]
表示方法参数的对象数组 Expression 。
返回
属性等于、属性设置为MethodInfo表示指定static(Shared在 Visual Basic 中)方法和Arguments属性设置为指定参数的属性。MethodCallNodeTypeMethodCallExpression
- 属性
例外
type 或 methodName 为 null.
没有名称为 methodName、类型参数匹配 typeArguments以及其参数类型匹配 arguments 在或其基类型中找到 type 的方法。
-或-
多个名称为 methodName的方法,其类型参数匹配 typeArguments,以及其参数类型匹配 arguments 在或其基类型中找到 type 。
注解
Type生成的MethodCallExpression属性等于方法methodName的返回类型。 属性 Object 为 null.
适用于
Call(MethodInfo, Expression, Expression, Expression)
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
创建一个 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
表示第一个参数的 < a0/>
- arg1
- Expression
表示第二个参数的 < a0/>
- arg2
- Expression
表示第三个参数的 < a0/>
返回
一个MethodCallExpression属性NodeType等于Call和ObjectMethod属性设置为指定值。
例外
method 为 null。
适用于
Call(Expression, String, Type[], Expression[])
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
通过调用适当的工厂方法创建表示 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);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Calling a generic method requires dynamic code generation. This can be suppressed if the method is not generic.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Creating Expressions requires unreferenced code because the members being referenced by the Expression may be trimmed.")]
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);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Creating Expressions requires unreferenced code because the members being referenced by the Expression may be trimmed.")]
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
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Calling a generic method requires dynamic code generation. This can be suppressed if the method is not generic.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Creating Expressions requires unreferenced code because the members being referenced by the Expression may be trimmed.")>]
static member Call : System.Linq.Expressions.Expression * string * Type[] * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.MethodCallExpression
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Creating Expressions requires unreferenced code because the members being referenced by the Expression may be trimmed.")>]
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
Expression其Type属性值将搜索特定方法。
- methodName
- String
方法的名称。
- arguments
- Expression[]
一个 Expression 对象数组,表示方法的参数。
返回
MethodCallExpression一个属性NodeType等于Call,Object属性等于instance,Method设置为MethodInfo表示指定实例方法的属性,并Arguments设置为指定的参数。
- 属性
例外
instance 或 methodName 为 null.
名称为 methodName、类型参数匹配 typeArguments以及其参数类型匹配 arguments 在 中的 instance方法。类型或其基类型。
-或-
多个名称为methodName的方法,其类型参数匹配typeArguments,并在其中instance找到其参数类型匹配arguments。类型或其基类型。
注解
Type生成的MethodCallExpression属性等于方法methodName的返回类型。
适用于
Call(Expression, MethodInfo, Expression, Expression)
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
创建一个 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 指定实例调用的实例。 (为静态方法传递 null(在 Visual Basic 中共享) 方法)。
- method
- MethodInfo
表示 MethodInfo 目标方法的表示。
- arg0
- Expression
表示第一个参数的 < a0/>
- arg1
- Expression
表示第二个参数的 < a0/>
返回
一个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)
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
创建一个 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
表示第一个参数的 < a0/>
- arg1
- Expression
表示第二个参数的 < a0/>
- arg2
- Expression
表示第三个参数的 < a0/>
- arg3
- Expression
表示第四个参数的 < a0/>
返回
一个MethodCallExpression属性NodeType等于Call和ObjectMethod属性设置为指定值。
例外
method 为 null。
适用于
Call(Expression, MethodInfo, Expression[])
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
创建一个 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实例方法调用的实例(在 staticShared Visual Basic 中传递null)方法的实例。
- method
- MethodInfo
一个 MethodInfo 设置为 Method 等于的属性。
- arguments
- Expression[]
用于填充Arguments集合的对象数组Expression。
返回
一个属性
例外
method 是 null。
-或-
instance
method表示null实例方法。
-或-
arguments 不是 null ,它的一个或多个元素是 null。
instance.类型不能分配给方法 method的声明类型。
-或-
中的 arguments 元素数不等于方法 method所表示的参数数。
-或-
一个或多个元素 arguments 不能分配给方法 method所表示的相应参数。
注解
若要表示对 static (Shared在 Visual Basic) 方法的调用,在调用此方法或改为调用Call时传入null参数instance。
如果 method 表示实例方法, Type 则必须将属性 instance 分配给方法 method所表示的声明类型。
null如果没有arguments,它必须具有与方法method所表示的参数数相同的元素数。 每个元素arguments都必须不能null,并且必须可分配给引用后的相应参数method。
注释
仅当相应的方法参数的类型为时 Expression,才会引用元素。 引用表示元素包装在节点 Quote 中。 生成的节点是其属性为
生成的ArgumentsMethodCallExpression属性为空(如果arguments为 null)。 否则,它包含与其中一些元素相同的元素 arguments,其中一些元素可能会被引用。
Type生成的MethodCallExpression属性等于方法method的返回类型。
适用于
Call(Expression, MethodInfo, IEnumerable<Expression>)
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
创建一个 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设置为等于(Shared在 Visual Basic 中传递staticnullObject)方法的属性。
- method
- MethodInfo
一个 MethodInfo 设置为 Method 等于的属性。
- arguments
- IEnumerable<Expression>
IEnumerable<T>包含Expression用于填充Arguments集合的对象。
返回
一个属性
例外
instance.类型不能分配给方法 method的声明类型。
-或-
中的 arguments 元素数不等于方法 method所表示的参数数。
-或-
一个或多个元素 arguments 不能分配给方法 method所表示的相应参数。
注解
若要表示对 static (Shared在 Visual Basic) 方法的调用,在调用此方法或改为调用Call时传入null参数instance。
如果 method 表示实例方法, Type 则必须将属性 instance 分配给方法 method所表示的声明类型。
null如果没有arguments,它必须具有与方法method所表示的参数数相同的元素数。 每个元素arguments都必须不能null,并且必须可分配给引用后的相应参数method。
注释
仅当相应的方法参数的类型为时 Expression,才会引用元素。 引用表示元素包装在节点 Quote 中。 生成的节点是其属性为
生成的ArgumentsMethodCallExpression属性为空(如果arguments为 null)。 否则,它包含与其中一些元素相同的元素 arguments,其中一些元素可能会被引用。
Type生成的MethodCallExpression属性等于方法method的返回类型。
适用于
Call(MethodInfo, Expression[])
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
创建一个MethodCallExpression表示对具有参数的 (Shared在 Visual Basic) 方法的调用static。
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 表示(Shared 在 Visual Basic 中)方法,用于设置属性 Method 等于的属性。
- arguments
- Expression[]
用于填充Arguments集合的对象数组Expression。
返回
一个MethodCallExpression属性NodeType等于Call和MethodArguments属性设置为指定值。
例外
method 是 null。
中的 arguments 元素数不等于方法 method所表示的参数数。
-或-
一个或多个元素 arguments 不能分配给方法 method所表示的相应参数。
注解
null如果没有arguments,它必须具有与方法method所表示的参数数相同的元素数。 每个元素arguments都必须不能null,并且必须可分配给引用后的相应参数method。
注释
仅当相应的方法参数的类型为时 Expression,才会引用元素。 引用表示元素包装在节点 Quote 中。 生成的节点是其属性为
生成的ArgumentsMethodCallExpression属性为空(如果arguments为 null)。 否则,它包含与其中一些元素相同的元素 arguments,其中一些元素可能会被引用。
Type生成的MethodCallExpression属性等于方法method的返回类型。 属性 Object 为 null.
适用于
Call(MethodInfo, Expression)
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
创建一个MethodCallExpression表示对采用一个参数的 (Shared在 Visual Basic) 方法的调用static。
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
表示第一个参数的 < a0/>
返回
一个MethodCallExpression属性NodeType等于Call和ObjectMethod属性设置为指定值。
例外
method 为 null。
示例
下面的示例演示如何创建调用采用一个参数的 (Shared在 Visual Basic) 方法中调用static的表达式。
// 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>)
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
创建一个 MethodCallExpression 表示对静态(在 Visual Basic 中共享)方法的调用。
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属性NodeType等于Call和ObjectMethod属性设置为指定值。
适用于
Call(Expression, MethodInfo)
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
创建一个 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实例方法调用的实例(在 staticShared Visual Basic 中传递null)方法的实例。
- method
- MethodInfo
一个 MethodInfo 设置为 Method 等于的属性。
返回
一个MethodCallExpression属性NodeType等于Call和ObjectMethod属性设置为指定值。
例外
instance.类型不能分配给方法 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
注解
若要表示对 static (Shared在 Visual Basic) 方法的调用,在调用此方法时为instancenull参数传入。
如果 method 表示实例方法, Type 则必须将属性 instance 分配给方法 method所表示的声明类型。
Arguments生成的MethodCallExpression属性为空。 该 Type 属性等于方法 method的返回类型。
适用于
Call(MethodInfo, Expression, Expression)
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
- Source:
- MethodCallExpression.cs
创建一个 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
表示第一个参数的 < a0/>
- arg1
- Expression
表示第二个参数的 < a0/>
返回
一个MethodCallExpression属性NodeType等于Call和ObjectMethod属性设置为指定值。
例外
method 为 null。