MethodCallExpression 类

定义

表示对静态方法或实例方法的调用。Represents a call to either static or an instance method.

public ref class MethodCallExpression : System::Linq::Expressions::Expression, System::Linq::Expressions::IArgumentProvider
public class MethodCallExpression : System.Linq.Expressions.Expression, System.Linq.Expressions.IArgumentProvider
type MethodCallExpression = class
    inherit Expression
    interface IArgumentProvider
Public Class MethodCallExpression
Inherits Expression
Implements IArgumentProvider
继承
MethodCallExpression
实现

示例

下面的示例创建一个 MethodCallExpression 对象,该对象表示编入二维数组的索引。The following example creates a MethodCallExpression object that represents indexing into a two-dimensional array.

string[,] gradeArray =
    { {"chemistry", "history", "mathematics"}, {"78", "61", "82"} };

System.Linq.Expressions.Expression arrayExpression =
    System.Linq.Expressions.Expression.Constant(gradeArray);

// Create a MethodCallExpression that represents indexing
// into the two-dimensional array 'gradeArray' at (0, 2).
// Executing the expression would return "mathematics".
System.Linq.Expressions.MethodCallExpression methodCallExpression =
    System.Linq.Expressions.Expression.ArrayIndex(
        arrayExpression,
        System.Linq.Expressions.Expression.Constant(0),
        System.Linq.Expressions.Expression.Constant(2));

Console.WriteLine(methodCallExpression.ToString());

// This code produces the following output:
//
// value(System.String[,]).Get(0, 2)
Dim gradeArray(,) As String = _
    {{"chemistry", "history", "mathematics"}, {"78", "61", "82"}}

Dim arrayExpression As System.Linq.Expressions.Expression = _
    System.Linq.Expressions.Expression.Constant(gradeArray)

' Create a MethodCallExpression that represents indexing
' into the two-dimensional array 'gradeArray' at (0, 2).
' Executing the expression would return "mathematics".
Dim methodCallExpression As System.Linq.Expressions.MethodCallExpression = _
    System.Linq.Expressions.Expression.ArrayIndex( _
        arrayExpression, _
        System.Linq.Expressions.Expression.Constant(0), _
        System.Linq.Expressions.Expression.Constant(2))

Console.WriteLine(methodCallExpression.ToString())

' This code produces the following output:
'
' value(System.String[,]).Get(0, 2)

注解

使用 CallArrayIndexArrayIndex 工厂方法来创建 MethodCallExpressionUse the Call, ArrayIndex, or ArrayIndex factory method to create a MethodCallExpression.

CallMethodCallExpression 对象的 NodeType 属性的值。The value of the NodeType property of a MethodCallExpression object is Call.

属性

Arguments

获取表示所调用方法的参数的表达式集合。Gets a collection of expressions that represent arguments of the called method.

CanReduce

指示可将节点简化为更简单的节点。Indicates that the node can be reduced to a simpler node. 如果返回 true,则可以调用 Reduce() 以生成简化形式。If this returns true, Reduce() can be called to produce the reduced form.

(继承自 Expression)
Method

获取要调用的方法的 MethodInfoGets the MethodInfo for the method to be called.

NodeType

返回此 Expression 的节点类型。Returns the node type of this Expression.

Object

获取表示实例方法调用的实例或静态方法调用的 null 的 ExpressionGets the Expression that represents the instance for instance method calls or null for static method calls.

Type

获取此 Expression 表示的表达式的静态类型。Gets the static type of the expression that this Expression represents.

方法

Accept(ExpressionVisitor)

调度到此节点类型的特定 Visit 方法。Dispatches to the specific visit method for this node type. 例如,MethodCallExpression 调用 VisitMethodCall(MethodCallExpression)For example, MethodCallExpression calls the VisitMethodCall(MethodCallExpression).

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
Reduce()

将此节点简化为更简单的表达式。Reduces this node to a simpler expression. 如果 CanReduce 返回 true,则它应返回有效的表达式。If CanReduce returns true, this should return a valid expression. 此方法可以返回本身必须简化的另一个节点。This method can return another node which itself must be reduced.

(继承自 Expression)
ReduceAndCheck()

将此节点简化为更简单的表达式。Reduces this node to a simpler expression. 如果 CanReduce 返回 true,则它应返回有效的表达式。If CanReduce returns true, this should return a valid expression. 此方法可以返回本身必须简化的另一个节点。This method can return another node which itself must be reduced.

(继承自 Expression)
ReduceExtensions()

将表达式简化为已知节点类型(即非 Extension 节点)或仅在此类型为已知类型时返回表达式。Reduces the expression to a known node type (that is not an Extension node) or just returns the expression if it is already a known type.

(继承自 Expression)
ToString()

返回 Expression 的的文本化表示形式。Returns a textual representation of the Expression.

(继承自 Expression)
Update(Expression, IEnumerable<Expression>)

创建一个新的表达式,它类似于此表达式,但使用所提供的子级。Creates a new expression that is like this one, but using the supplied children. 如果所有子级均相同,它将返回此表达式。If all of the children are the same, it will return this expression.

VisitChildren(ExpressionVisitor)

简化节点,然后对简化的表达式调用访问者委托。Reduces the node and then calls the visitor delegate on the reduced expression. 该方法在节点不可简化时引发异常。The method throws an exception if the node is not reducible.

(继承自 Expression)

显式接口实现

IArgumentProvider.ArgumentCount

返回表达式树节点的参数数目。Returns the number of arguments to the expression tree node. 不应使用此成员。You should not use this member. 仅在程序集重构时公开,并且仅用于内部性能优化。It is only public due to assembly refactoring, and it is used internally for performance optimizations.

IArgumentProvider.GetArgument(Int32)

索引时返回自变量,当索引超出界限时引发。Returns the argument at index, throwing if index is out of bounds. 不应使用此成员。You should not use this member. 仅在程序集重构时公开,并且仅用于内部性能优化。It is only public due to assembly refactoring, and it is used internally for performance optimizations.

适用于