Expression.Or 方法

定義

會產生 BinaryExpression 一個代表位元運算 OR 的 a。

多載

名稱 Description
Or(Expression, Expression)

會產生 BinaryExpression 一個代表位元運算 OR 的 a。

Or(Expression, Expression, MethodInfo)

會產生 BinaryExpression 一個代表位元運算 OR 的 a。

Or(Expression, Expression)

來源:
BinaryExpression.cs
來源:
BinaryExpression.cs
來源:
BinaryExpression.cs
來源:
BinaryExpression.cs
來源:
BinaryExpression.cs

會產生 BinaryExpression 一個代表位元運算 OR 的 a。

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

參數

left
Expression

Expression A 將屬性Left設為 。

right
Expression

Expression A 將屬性Right設為 。

傳回

BinaryExpression一個屬性等NodeType於 ,OrLeftRight 屬性設定為指定值的 a。

例外狀況

leftrightnull

OR 元運算子對 未定義 left。類型與 right。打字。

範例

以下程式碼範例說明如何建立一個表示邏輯 OR 運算的表達式。

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

// This expression perfroms a logical OR operation
// on its two arguments. Both arguments must be of the same type,
// which can be boolean or integer.
Expression orExpr = Expression.Or(
    Expression.Constant(true),
    Expression.Constant(false)
);

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

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

// This code example produces the following output:
//
// (True Or False)
// True
' Add the following directive to your file:
' Imports System.Linq.Expressions  

' This expression perfroms a logical OR operation
' on its two arguments. Both arguments must be of the same type,
' which can be Boolean or integer.             
Dim orExpr As Expression = Expression.Or(
     Expression.Constant(True),
     Expression.Constant(False)
 )

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

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

' This code example produces the following output:
'
' (True Or False)
' True

備註

結果 BinaryExpression 中,該屬性設定 Method 為實作方法。 屬性 Type 會設定為節點的類型。 如果節點被取消,IsLiftedIsLiftedToNull 屬性都是 true。 否則,它們是 false。 IsEditable 屬性為 true。

下列資訊描述實作方法、節點類型,以及節點是否已解除。

實作方法

以下規則決定了操作的實作方法:

  • 如果 Typerightleft屬性代表使用者定義的型別,該型別會超載位元運算OR子,那麼代表該方法的 就是MethodInfo實作方法。

  • 否則,若 left。類型與 right。類型是整數型或布林型,實作方法是 null

節點類型與提升與非提升

如果實作方法不是 null

  • 如果 left.型別和 right.型別可以指派給實作方法的對應參數型別,則節點不會被解除。 節點的類型是實作方法的傳回型別。

  • 如果符合下列兩個條件,則節點會提升,並且該節點的類型是對應至實作方法傳回型別的可空類型:

    • left.型別 與 right.型別 都是實值型別,其中至少一個可為 Null,而對應的不可為 Null 型別等於實作方法的對應參數類型。

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

如果實作方法為 null

  • 如果left.類型與right.類型都是不可為 Null 的,節點不會被提升。 節點的型別是預先定義的位元運算 OR 子的結果型態。

  • 如果 left.Type 和 right.Type 都是可為 null 的,則該節點會提升。 節點的型別是可空的型別,對應於預先定義的位元運算 OR 子的結果型別。

適用於

Or(Expression, Expression, MethodInfo)

來源:
BinaryExpression.cs
來源:
BinaryExpression.cs
來源:
BinaryExpression.cs
來源:
BinaryExpression.cs
來源:
BinaryExpression.cs

會產生 BinaryExpression 一個代表位元運算 OR 的 a。

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

參數

left
Expression

Expression A 將屬性Left設為 。

right
Expression

Expression A 將屬性Right設為 。

method
MethodInfo

MethodInfo A 將屬性設Method為 。

傳回

BinaryExpression A 的屬性等NodeTypeOr ,且Left屬性為 ,RightMethod屬性設定為指定的值。

例外狀況

leftrightnull

method不是null,且它所代表的方法回傳 void, 是 (在 staticShared Visual Basic 中),或不恰好接受兩個參數。

methodnull ,且位元 OR 運算子對 不定義。 left類型與 right。打字。

備註

結果 BinaryExpression 中,該屬性設定 Method 為實作方法。 屬性 Type 會設定為節點的類型。 如果節點被取消,IsLiftedIsLiftedToNull 屬性都是 true。 否則,它們是 false。 IsEditable 屬性為 true。

下列資訊描述實作方法、節點類型,以及節點是否已解除。

實作方法

以下規則決定了操作的實作方法:

  • 如果method不是null,且它代表一個非空staticShared(Visual Basic 中)且接受兩個參數的方法,則它是實作方法。

  • 否則,若 Typeleftright屬性代表使用者定義的型別,且會超載位元運算OR子,則MethodInfo代表該方法的 即為實作方法。

  • 否則,若 left。類型與 right。類型是整數型或布林型,實作方法是 null

節點類型與提升與非提升

如果實作方法不是 null

  • 如果 left.型別和 right.型別可以指派給實作方法的對應參數型別,則節點不會被解除。 節點的類型是實作方法的傳回型別。

  • 如果符合下列兩個條件,則節點會提升,並且該節點的類型是對應至實作方法傳回型別的可空類型:

    • left.型別 與 right.型別 都是實值型別,其中至少一個可為 Null,而對應的不可為 Null 型別等於實作方法的對應參數類型。

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

如果實作方法為 null

  • 如果left.類型與right.類型都是不可為 Null 的,節點不會被提升。 節點的型別是預先定義的位元運算 OR 子的結果型態。

  • 如果 left.Type 和 right.Type 都是可為 null 的,則該節點會提升。 節點的型別是可空的型別,對應於預先定義的位元運算 OR 子的結果型別。

適用於