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 具有特定节点类型(由属性表示)的工厂方法 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 Method
Add Add
AddChecked AddChecked
Divide Divide
Modulo Modulo
Multiply Multiply
MultiplyChecked MultiplyChecked
Power Power
Subtract Subtract
SubtractChecked SubtractChecked

按位运算Bitwise Operations

节点类型Node Type 工厂方法Factory Method
And And
Or Or
ExclusiveOr ExclusiveOr

移位运算Shift Operations

节点类型Node Type 工厂方法Factory Method
LeftShift LeftShift
RightShift RightShift

条件布尔运算Conditional Boolean Operations

节点类型Node Type 工厂方法Factory Method
AndAlso AndAlso
OrElse OrElse

比较运算Comparison Operations

节点类型Node Type 工厂方法Factory Method
Equal Equal
NotEqual NotEqual
GreaterThanOrEqual GreaterThanOrEqual
GreaterThan GreaterThan
LessThan LessThan
LessThanOrEqual LessThanOrEqual

合并运算Coalescing Operations

节点类型Node Type 工厂方法Factory Method
Coalesce Coalesce

数组索引操作Array Indexing Operations

节点类型Node Type 工厂方法Factory Method
ArrayIndex ArrayIndex

此外, MakeBinary 还可以使用这些方法来创建 BinaryExpressionIn addition, the MakeBinary methods can also be used to create a BinaryExpression. 这些工厂方法可用于创建 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)

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

Accept(ExpressionVisitor)

调度到此节点类型的特定 Visit 方法。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)

适用于