ConditionalExpression クラス

定義

条件演算子を持つ式を表します。

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

次のコード例は、条件ステートメントを表す式を作成する方法を示しています。 最初の引数が trueに評価された場合、2 番目の引数が実行されます。それ以外の場合は、3 番目の引数が実行されます。

// 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 ファクトリ メソッドを使用します。

ConditionalExpressionNodeTypeConditional

プロパティ

名前 説明
CanReduce

ノードを単純なノードに縮小できることを示します。 これが true を返す場合は、Reduce() を呼び出して縮小形式を生成できます。

(継承元 Expression)
IfFalse

テストが falseに評価された場合に実行する式を取得します。

IfTrue

テストが trueに評価された場合に実行する式を取得します。

NodeType

この式のノード型を返します。 拡張ノードは、このメソッドをオーバーライドするときに Extension を返す必要があります。

NodeType

この Expressionのノードの種類を取得します。

(継承元 Expression)
Test

条件付き操作のテストを取得します。

Type

この Expression が表す式の静的な型を取得します。

Type

この Expression が表す式の静的な型を取得します。

(継承元 Expression)

メソッド

名前 説明
Accept(ExpressionVisitor)

このノード タイプの特定の visit メソッドにディスパッチします。 たとえば、 MethodCallExpressionVisitMethodCall(MethodCallExpression)を呼び出します。

Equals(Object)

指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
Reduce()

このノードを単純な式に減らします。 CanReduce が true を返す場合は、有効な式を返す必要があります。 このメソッドは、それ自体を減らす必要がある別のノードを返すことができます。

(継承元 Expression)
ReduceAndCheck()

このノードを単純な式に減らします。 CanReduce が true を返す場合は、有効な式を返す必要があります。 このメソッドは、それ自体を減らす必要がある別のノードを返すことができます。

(継承元 Expression)
ReduceExtensions()

式を既知のノード型 (拡張ノードではない) に減らすか、既に既知の型である場合は式を返します。

(継承元 Expression)
ToString()

Expressionのテキスト表現を返します。

(継承元 Expression)
Update(Expression, Expression, Expression)

次のような新しい式を作成しますが、指定された子を使用します。 すべての子が同じ場合、この式が返されます。

VisitChildren(ExpressionVisitor)

ノードを減らし、縮小された式でビジター デリゲートを呼び出します。 ノードが縮小できない場合、メソッドは例外をスローします。

(継承元 Expression)

適用対象