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

ConditionalExpressionNodeType ですConditional

プロパティ

CanReduce

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

(継承元 Expression)
IfFalse

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

IfTrue

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

NodeType

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

NodeType

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

(継承元 Expression)
Test

条件演算のテストを取得します。

Type

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

Type

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

(継承元 Expression)

メソッド

Accept(ExpressionVisitor)

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

Accept(ExpressionVisitor)

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

(継承元 Expression)
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)

ノードを単純化し、単純化された式の visitor デリゲートを呼び出します。 ノードを単純化できない場合、このメソッドは例外をスローします。

(継承元 Expression)

適用対象