ConditionalExpression ConditionalExpression ConditionalExpression ConditionalExpression Class

定義

条件演算子を持つ式を表します。Represents an expression that has a conditional operator.

public ref class ConditionalExpression : System::Linq::Expressions::Expression
public class ConditionalExpression : System.Linq.Expressions.Expression
type ConditionalExpression = class
    inherit Expression
Public Class ConditionalExpression
Inherits Expression
継承
ConditionalExpressionConditionalExpressionConditionalExpressionConditionalExpression

次のコード例では、条件付きステートメントを表す式を作成する方法を示します。The following code example shows how to create an expression that represents a conditional statement. 最初の引数が評価された場合trueは、2 番目の引数が実行された以外の場合、3 番目の引数を実行します。If the first argument evaluates to true, the second argument is executed; otherwise, the third argument is executed.

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

int num = 100;

// This expression represents a conditional operation. 
// It evaluates the test (first expression) and
// executes the iftrue block (second argument) if the test evaluates to true, 
// or the iffalse block (third argument) if the test evaluates to false.
Expression conditionExpr = Expression.Condition(
                           Expression.Constant(num > 10),
                           Expression.Constant("num is greater than 10"),
                           Expression.Constant("num is smaller than 10")
                         );

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

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

// This code example produces the following output:
//
// IIF("True", "num is greater than 10", "num is smaller than 10")
// num is greater than 10
' Add the following directive to your file:
' Imports System.Linq.Expressions  

Dim num As Integer = 100

' This expression represents a conditional operation; 
' it will evaluate the test (first expression) and
' execute the ifTrue block (second argument) if the test evaluates to true, 
' or the ifFalse block (third argument) if the test evaluates to false.
Dim conditionExpr As Expression = Expression.Condition(
                            Expression.Constant(num > 10),
                            Expression.Constant("n is greater than 10"),
                            Expression.Constant("n is smaller than 10")
                        )

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

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

' This code example produces the following output:
'
' IIF("True", "num is greater than 10", "num is smaller than 10")
' num is greater than 10

注釈

使用して、Conditionを作成するファクトリ メソッドをConditionalExpressionします。Use the Condition factory method to create a ConditionalExpression.

NodeTypeConditionalExpressionConditionalします。The NodeType of a ConditionalExpression is Conditional.

プロパティ

CanReduce CanReduce CanReduce 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.

(Inherited from Expression)
IfFalse IfFalse IfFalse IfFalse

テストで false と評価される場合に実行する式を取得します。Gets the expression to execute if the test evaluates to false.

IfTrue IfTrue IfTrue IfTrue

テストで true と評価される場合に実行する式を取得します。Gets the expression to execute if the test evaluates to true.

NodeType NodeType NodeType NodeType

この式のノード型を返します。Returns the node type of this expression. 拡張ノードは、このメソッドをオーバーライドする際に Extension を返す必要があります。Extension nodes should return Extension when overriding this method.

Test Test Test Test

条件演算のテストを取得します。Gets the test of the conditional operation.

Type Type Type Type

この Expression が表す式の静的な型を取得します。Gets the static type of the expression that this Expression represents.

メソッド

Accept(ExpressionVisitor) Accept(ExpressionVisitor) Accept(ExpressionVisitor) Accept(ExpressionVisitor)

このノード型の特定の Visit メソッドにデスパッチします。Dispatches to the specific visit method for this node type. たとえば、MethodCallExpressionVisitMethodCall(MethodCallExpression) を呼び出します。For example, MethodCallExpression calls the VisitMethodCall(MethodCallExpression).

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

指定したオブジェクトが、現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
Reduce() Reduce() Reduce() 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.

(Inherited from Expression)
ReduceAndCheck() ReduceAndCheck() ReduceAndCheck() 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.

(Inherited from Expression)
ReduceExtensions() ReduceExtensions() ReduceExtensions() ReduceExtensions()

式を既知のノード型 (拡張ノードではない型) に単純化し、それが既に既知の型である場合は単に式を返します。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.

(Inherited from Expression)
ToString() ToString() ToString() ToString()

Expression のテキスト表現を返します。Returns a textual representation of the Expression.

(Inherited from Expression)
Update(Expression, Expression, Expression) Update(Expression, Expression, Expression) Update(Expression, Expression, Expression) Update(Expression, Expression, 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) VisitChildren(ExpressionVisitor) VisitChildren(ExpressionVisitor) VisitChildren(ExpressionVisitor)

ノードを単純化し、単純化された式の visitor デリゲートを呼び出します。Reduces the node and then calls the visitor delegate on the reduced expression. ノードを単純化できない場合、このメソッドは例外をスローします。The method throws an exception if the node is not reducible.

(Inherited from Expression)

適用対象