Expression.ExclusiveOr 方法

定义

创建一个表示按位 BinaryExpression 运算的 XOR

重载

ExclusiveOr(Expression, Expression, MethodInfo)

通过对用户定义的类型使用 BinaryExpression,创建一个表示按位 XOR 运算的 op_ExclusiveOr。 可指定实现方法。

ExclusiveOr(Expression, Expression)

通过对用户定义的类型使用 BinaryExpression,创建一个表示按位 XOR 运算的 op_ExclusiveOr

ExclusiveOr(Expression, Expression, MethodInfo)

Source:
BinaryExpression.cs
Source:
BinaryExpression.cs
Source:
BinaryExpression.cs

通过对用户定义的类型使用 BinaryExpression,创建一个表示按位 XOR 运算的 op_ExclusiveOr。 可指定实现方法。

public:
 static System::Linq::Expressions::BinaryExpression ^ ExclusiveOr(System::Linq::Expressions::Expression ^ left, System::Linq::Expressions::Expression ^ right, System::Reflection::MethodInfo ^ method);
public static System.Linq.Expressions.BinaryExpression ExclusiveOr (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, System.Reflection.MethodInfo method);
public static System.Linq.Expressions.BinaryExpression ExclusiveOr (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, System.Reflection.MethodInfo? method);
static member ExclusiveOr : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Reflection.MethodInfo -> System.Linq.Expressions.BinaryExpression
Public Shared Function ExclusiveOr (left As Expression, right As Expression, method As MethodInfo) As BinaryExpression

参数

left
Expression

要将 Expression 属性设置为与其相等的 Left

right
Expression

要将 Expression 属性设置为与其相等的 Right

method
MethodInfo

要将 MethodInfo 属性设置为与其相等的 Method

返回

一个 BinaryExpression,其 NodeType 属性等于 ExclusiveOr,并且其 LeftRightMethod 属性设置为指定值。

例外

leftrightnull

method 不是 null,它所表示的方法返回 void,而不是 static(Visual Basic 中为 Shared),或者并非采用两个参数。

methodnull,且没有为 left.Type 和 right.Type 定义 XOR 运算符。

注解

生成的 BinaryExpressionMethod 属性设置为 实现方法。 属性 Type 设置为节点的类型。 如果节点已提升,则 IsLiftedIsLiftedToNull 属性均为 true。 否则,它们为 falseConversion 属性为 null

以下信息介绍了实现方法、节点类型以及是否提升节点。

实现方法

以下规则确定为操作选择的实现方法:

  • 如果 method 不是 null ,它表示非 void, static (Shared Visual Basic) 方法中采用两个参数,则为实现方法。

  • 否则,如果 Typerightleft 属性表示重载XOR运算符的用户定义类型,MethodInfo则表示该方法的 就是实现方法。

  • 否则,如果 为 ,则为 left。键入 和 right。类型是整型类型或布尔类型,实现方法是 null

节点类型和提升与非提升

如果实现方法不是 null

  • 如果 left为 。键入 和 right。类型可分配给实现方法的相应参数类型,节点不会提升。 节点的类型是实现方法的返回类型。

  • 如果满足以下两个条件,则会提升节点,节点的类型是对应于实现方法的返回类型的可为空类型:

    • left.键入 和 right。类型是两种值类型,其中至少有一种可为 null,相应的不可为 null 类型等于实现方法的相应参数类型。

    • 实现方法的返回类型是不可为 null 的值类型。

如果实现方法是 null

  • 如果 left为 。键入 和 right。类型都是不可为 null 的,节点不会解除。 节点的类型是预定义 XOR 运算符的结果类型。

  • 如果 left为 。键入 和 right。类型都是可以为 null 的,节点是提升的。 节点的类型是对应于预定义 XOR 运算符的结果类型的可为空类型。

适用于

ExclusiveOr(Expression, Expression)

Source:
BinaryExpression.cs
Source:
BinaryExpression.cs
Source:
BinaryExpression.cs

通过对用户定义的类型使用 BinaryExpression,创建一个表示按位 XOR 运算的 op_ExclusiveOr

public:
 static System::Linq::Expressions::BinaryExpression ^ ExclusiveOr(System::Linq::Expressions::Expression ^ left, System::Linq::Expressions::Expression ^ right);
public static System.Linq.Expressions.BinaryExpression ExclusiveOr (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right);
static member ExclusiveOr : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.BinaryExpression
Public Shared Function ExclusiveOr (left As Expression, right As Expression) As BinaryExpression

参数

left
Expression

要将 Expression 属性设置为与其相等的 Left

right
Expression

要将 Expression 属性设置为与其相等的 Right

返回

一个 BinaryExpression,其 NodeType 属性等于 ExclusiveOr,并且其 LeftRight 属性设置为指定值。

例外

leftrightnull

没有为 left.Type 和 right.Type 定义 XOR 运算符。

示例

下面的代码示例演示如何创建表示逻辑 XOR 操作的表达式。

// Add the following directive to your file:
// using System.Linq.Expressions;

// This expression represents an exclusive OR operation for its two arguments.
// Both arguments must be of the same type,
// which can be either integer or boolean.

Expression exclusiveOrExpr = Expression.ExclusiveOr(
    Expression.Constant(5),
    Expression.Constant(3)
);

// Print out the expression.
Console.WriteLine(exclusiveOrExpr.ToString());

// The following statement first creates an expression tree,
// then compiles it, and then executes it.
Console.WriteLine(
    Expression.Lambda<Func<int>>(exclusiveOrExpr).Compile()());

// The XOR operation is performed as follows:
// 101 xor 011 = 110

// This code example produces the following output:
//
// (5 ^ 3)
// 6
' Add the following directive to your file:
' Imports System.Linq.Expressions   

' This expression represents an exclusive OR operation for its two arguments.
' Both arguments must be of the same type, 
' which can be either integer or Boolean.

Dim exclusiveOrExpr As Expression = Expression.ExclusiveOr(
     Expression.Constant(5),
     Expression.Constant(3)
 )

' Print the expression.
Console.WriteLine(exclusiveOrExpr.ToString())

' The following statement first creates an expression tree,
' then compiles it, and then executes it.           
Console.WriteLine(
    Expression.Lambda(Of Func(Of Integer))(exclusiveOrExpr).Compile()())

' The XOR operation is performed as follows:
' 101 xor 011 = 110

' This code example produces the following output:
'
' (5 ^ 3)
' 6

注解

生成的 BinaryExpressionMethod 属性设置为 实现方法。 属性 Type 设置为节点的类型。 如果节点已提升,则 IsLiftedIsLiftedToNull 属性均为 true。 否则,它们为 falseConversion 属性为 null

以下信息介绍了实现方法、节点类型以及是否提升节点。

实现方法

以下规则确定操作的实现方法:

  • Type如果 或 rightleft 属性表示重载XOR运算符的用户定义类型,MethodInfo则表示该方法的 是实现方法。

  • 否则,如果 为 ,则为 left。键入 和 right。类型是整型类型或布尔类型,实现方法是 null

节点类型和提升与非提升

如果实现方法不是 null

  • 如果 left为 。键入 和 right。类型可分配给实现方法的相应参数类型,节点不会提升。 节点的类型是实现方法的返回类型。

  • 如果满足以下两个条件,则会提升节点,节点的类型是对应于实现方法的返回类型的可为空类型:

    • left.键入 和 right。类型是两种值类型,其中至少有一种可为 null,相应的不可为 null 类型等于实现方法的相应参数类型。

    • 实现方法的返回类型是不可为 null 的值类型。

如果实现方法是 null

  • 如果 left为 。键入 和 right。类型都是不可为 null 的,节点不会解除。 节点的类型是预定义 XOR 运算符的结果类型。

  • 如果 left为 。键入 和 right。类型都是可以为 null 的,节点是提升的。 节点的类型是对应于预定义 XOR 运算符的结果类型的可为空类型。

适用于