BinaryExpression 類別

定義

代表具有二元運算子的運算式。Represents an expression that has a binary operator.

public ref class BinaryExpression : System::Linq::Expressions::Expression
public ref class BinaryExpression sealed : System::Linq::Expressions::Expression
public class BinaryExpression : System.Linq.Expressions.Expression
public sealed class BinaryExpression : System.Linq.Expressions.Expression
type BinaryExpression = class
    inherit Expression
Public Class BinaryExpression
Inherits Expression
Public NotInheritable Class BinaryExpression
Inherits Expression
繼承
BinaryExpression

範例

下列範例會建立一個 BinaryExpression 物件,代表另一個數位的減法。The following example creates a BinaryExpression object that represents the subtraction of one number from another.

// Create a BinaryExpression that represents subtracting 14 from 53.
System.Linq.Expressions.BinaryExpression binaryExpression =
    System.Linq.Expressions.Expression.MakeBinary(
        System.Linq.Expressions.ExpressionType.Subtract,
        System.Linq.Expressions.Expression.Constant(53),
        System.Linq.Expressions.Expression.Constant(14));

Console.WriteLine(binaryExpression.ToString());

// This code produces the following output:
//
// (53 - 14)
' Create a BinaryExpression that represents subtracting 14 from 53.
Dim binaryExpression As System.Linq.Expressions.BinaryExpression = _
    System.Linq.Expressions.Expression.MakeBinary( _
        System.Linq.Expressions.ExpressionType.Subtract, _
        System.Linq.Expressions.Expression.Constant(53), _
        System.Linq.Expressions.Expression.Constant(14))

Console.WriteLine(binaryExpression.ToString())

' This code produces the following output:
'
' (53 - 14)

備註

下表摘要說明可用來建立 BinaryExpression 具有特定節點類型(以屬性工作表示)的 factory 方法 NodeTypeThe following tables summarize the factory methods that can be used to create a BinaryExpression that has a specific node type, represented by the NodeType property. 每個資料表都包含特定作業類別的資訊,例如算術或位。Each table contains information for a specific class of operations such as arithmetic or bitwise.

二進位算數運算Binary Arithmetic Operations

節點類型Node Type Factory 方法Factory Method
Add Add
AddChecked AddChecked
Divide Divide
Modulo Modulo
Multiply Multiply
MultiplyChecked MultiplyChecked
Power Power
Subtract Subtract
SubtractChecked SubtractChecked

位運算Bitwise Operations

節點類型Node Type Factory 方法Factory Method
And And
Or Or
ExclusiveOr ExclusiveOr

移位作業Shift Operations

節點類型Node Type Factory 方法Factory Method
LeftShift LeftShift
RightShift RightShift

條件式布林值作業Conditional Boolean Operations

節點類型Node Type Factory 方法Factory Method
AndAlso AndAlso
OrElse OrElse

比較作業Comparison Operations

節點類型Node Type Factory 方法Factory Method
Equal Equal
NotEqual NotEqual
GreaterThanOrEqual GreaterThanOrEqual
GreaterThan GreaterThan
LessThan LessThan
LessThanOrEqual LessThanOrEqual

聯合作業Coalescing Operations

節點類型Node Type Factory 方法Factory Method
Coalesce Coalesce

陣列索引作業Array Indexing Operations

節點類型Node Type Factory 方法Factory Method
ArrayIndex ArrayIndex

此外, MakeBinary 方法也可以用來建立 BinaryExpressionIn addition, the MakeBinary methods can also be used to create a BinaryExpression. 這些 factory 方法可以用來建立 BinaryExpression 代表二進位運算之任何節點類型的。These factory methods can be used to create a BinaryExpression of any node type that represents a binary operation. 類型為的這些方法的參數會 NodeType 指定所需的節點類型。The parameter of these methods that is of type NodeType specifies the desired node type.

屬性

CanReduce

取得值,指出是否可以減少運算式樹狀架構的節點。Gets a value that indicates whether the expression tree node can be reduced.

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)
Conversion

取得聯合或複合指派運算所使用的型別轉換函式。Gets the type conversion function that is used by a coalescing or compound assignment operation.

IsLifted

取得值,這個值指出運算式樹狀節點是否表示對運算子的「消除」** 呼叫。Gets a value that indicates whether the expression tree node represents a lifted call to an operator.

IsLiftedToNull

取得值,這個值指出運算式樹狀節點是否表示對運算子的「消除」** 呼叫,該運算子的傳回型別對可為 Null 的型別已消除。Gets a value that indicates whether the expression tree node represents a lifted call to an operator whose return type is lifted to a nullable type.

Left

取得二元作業的左運算元。Gets the left operand of the binary operation.

Method

取得二元作業的實作方法。Gets the implementing method for the binary operation.

NodeType

取得這個 Expression 的節點類型。Gets the node type of this Expression.

(繼承來源 Expression)
Right

取得二元作業的右運算元。Gets the right operand of the binary operation.

Type

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

(繼承來源 Expression)

方法

Accept(ExpressionVisitor)

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

Accept(ExpressionVisitor)

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

(繼承來源 Expression)
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 the binary expression node to a simpler expression.

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, LambdaExpression, 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)

適用於