Expression.ExclusiveOr 方法

定義

建立表示位元 BinaryExpression 運算的 XOR

多載

ExclusiveOr(Expression, Expression, MethodInfo)

使用 BinaryExpression 做為使用者定義的類型,建立表示位元 XOR 運算的 op_ExclusiveOr。 實作的方法可加以指定。

ExclusiveOr(Expression, Expression)

使用 BinaryExpression 做為使用者定義的類型,建立表示位元 XOR 運算的 op_ExclusiveOr

ExclusiveOr(Expression, Expression, MethodInfo)

來源:
BinaryExpression.cs
來源:
BinaryExpression.cs
來源:
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 運算子。

備註

產生的 BinaryExpression 屬性 Method 會設定為實作方法。 屬性 Type 會設定為節點的類型。 如果節點隨即提升, IsLifted 則 和 IsLiftedToNull 屬性都是 true 。 否則,它們是 falseConversion 屬性為 null

下列資訊描述實作方法、節點類型,以及節點是否已隨即提升。

實作方法

下列規則會決定為作業選擇的實作方法:

  • 如果 method 不是 null ,而且它代表非 void, static (Shared Visual Basic) 方法中採用兩個引數,則為實作方法。

  • 否則,如果 Typerightleft 屬性代表多載 XOR 運算子的使用者定義型別, MethodInfo 則表示該方法的 是實作方法。

  • 否則,如果 left 為 。輸入 和 right 。類型是整數或布林型別,實作方法是 null

節點類型和隨即轉移與非增益的比較

如果實作方法不是 null

  • 如果為 left 。輸入 和 right 。類型可指派給實作方法的對應引數類型,節點不會隨即解除。 節點的類型是實作方法的傳回型別。

  • 如果滿足下列兩個條件,則會隨即啟動節點,而節點的類型是對應至實作方法之傳回型別的可為 Null 類型:

    • left.輸入 和 right 。類型都是至少一個可為 Null 且對應的不可為 Null 型別等於實作方法的對應引數型別。

    • 實作方法的傳回型別是不可為 Null 的實值型別。

如果實作方法為 null

  • 如果為 left 。輸入 和 right 。類型都是不可為 Null 的,節點不會隨即解除。 節點的類型是預先定義 XOR 運算子的結果類型。

  • 如果為 left 。輸入 和 right 。類型都是可為 Null 的,節點會隨即解除。 節點的類型是對應至預先定義 XOR 運算子結果類型的可為 Null 的類型。

適用於

ExclusiveOr(Expression, Expression)

來源:
BinaryExpression.cs
來源:
BinaryExpression.cs
來源:
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

備註

產生的 BinaryExpression 屬性 Method 會設定為實作方法。 屬性 Type 會設定為節點的類型。 如果節點隨即提升, IsLifted 則 和 IsLiftedToNull 屬性都是 true 。 否則,它們是 falseConversion 屬性為 null

下列資訊描述實作方法、節點類型,以及節點是否已隨即提升。

實作方法

下列規則會決定作業的實作方法:

  • Type如果 或 rightleft 屬性代表多載 XOR 運算子的使用者定義型別, MethodInfo 則表示該方法的 是實作方法。

  • 否則,如果 left 為 。輸入 和 right 。類型是整數或布林型別,實作方法是 null

節點類型和隨即轉移與非增益的比較

如果實作方法不是 null

  • 如果為 left 。輸入 和 right 。類型可指派給實作方法的對應引數類型,節點不會隨即解除。 節點的類型是實作方法的傳回型別。

  • 如果滿足下列兩個條件,則會隨即啟動節點,而節點的類型是對應至實作方法之傳回型別的可為 Null 類型:

    • left.輸入 和 right 。類型都是至少一個可為 Null 且對應的不可為 Null 型別等於實作方法的對應引數型別。

    • 實作方法的傳回型別是不可為 Null 的實值型別。

如果實作方法為 null

  • 如果為 left 。輸入 和 right 。類型都是不可為 Null 的,節點不會隨即解除。 節點的類型是預先定義 XOR 運算子的結果類型。

  • 如果為 left 。輸入 和 right 。類型都是可為 Null 的,節點會隨即解除。 節點的類型是對應至預先定義 XOR 運算子結果類型的可為 Null 的類型。

適用於