MethodCallExpression MethodCallExpression MethodCallExpression MethodCallExpression Class

定義

表示呼叫靜態或執行個體方法。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
繼承
MethodCallExpressionMethodCallExpressionMethodCallExpressionMethodCallExpression
實作

範例

下列範例會建立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)

備註

Call使用、 ArrayIndexMethodCallExpressionfactory 方法來建立。 ArrayIndexUse the Call, ArrayIndex, or ArrayIndex factory method to create a MethodCallExpression.

MethodCallExpression物件的NodeType屬性值為CallThe value of the NodeType property of a MethodCallExpression object is Call.

屬性

Arguments Arguments Arguments Arguments

取得運算式的集合,這些運算式表示所呼叫方法的引數。Gets a collection of expressions that represent arguments of the called method.

CanReduce CanReduce CanReduce 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.

(Inherited from Expression)
Method Method Method Method

取得要呼叫之方法的 MethodInfoGets the MethodInfo for the method to be called.

NodeType NodeType NodeType NodeType

傳回這個 Expression 的節點型別。Returns the node type of this Expression.

Object Object Object Object

取得 Expression,表示執行個體 (適用於執行個體方法呼叫) 或 Null (適用於靜態方法呼叫)。Gets the Expression that represents the instance for instance method calls or null for static method calls.

Type Type Type Type

取得此 Expression 代表之運算式的靜態類型。Gets the static type of the expression that this Expression represents.

方法

Accept(ExpressionVisitor) Accept(ExpressionVisitor) Accept(ExpressionVisitor) Accept(ExpressionVisitor)

分派給這個節點類型的特定造訪方法。Dispatches to the specific visit method for this node type. 例如,MethodCallExpression 會呼叫 VisitMethodCall(MethodCallExpression)For example, MethodCallExpression calls the VisitMethodCall(MethodCallExpression).

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
Reduce() Reduce() Reduce() 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.

(Inherited from Expression)
ReduceAndCheck() ReduceAndCheck() ReduceAndCheck() 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.

(Inherited from Expression)
ReduceExtensions() ReduceExtensions() ReduceExtensions() 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.

(Inherited from Expression)
ToString() ToString() ToString() ToString()

傳回 Expression 的文字表示。Returns a textual representation of the Expression.

(Inherited from Expression)
Update(Expression, IEnumerable<Expression>) Update(Expression, IEnumerable<Expression>) Update(Expression, IEnumerable<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) VisitChildren(ExpressionVisitor) VisitChildren(ExpressionVisitor) 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.

(Inherited from Expression)

明確介面實作

IArgumentProvider.ArgumentCount IArgumentProvider.ArgumentCount IArgumentProvider.ArgumentCount 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) IArgumentProvider.GetArgument(Int32) IArgumentProvider.GetArgument(Int32) 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.

適用於