Expression.IfThen(Expression, Expression) 메서드

정의

문이 있는 ConditionalExpression 조건부 블록을 나타내는 해당 if 블록을 만듭니다.

public:
 static System::Linq::Expressions::ConditionalExpression ^ IfThen(System::Linq::Expressions::Expression ^ test, System::Linq::Expressions::Expression ^ ifTrue);
public static System.Linq.Expressions.ConditionalExpression IfThen(System.Linq.Expressions.Expression test, System.Linq.Expressions.Expression ifTrue);
static member IfThen : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.ConditionalExpression
Public Shared Function IfThen (test As Expression, ifTrue As Expression) As ConditionalExpression

매개 변수

test
Expression

Expression 속성을 같게 Test 설정하는 값입니다.

ifTrue
Expression

Expression 속성을 같게 IfTrue 설정하는 값입니다.

반품

ConditionalExpression 속성이 NodeTypeConditionalTest, 속성IfTrue이 지정된 값으로 설정된 A입니다. 속성이 IfFalse 기본 식으로 설정되고 이 메서드에서 반환된 ConditionalExpression 결과 형식은 다음과 같습니다 Void.

예제

다음 코드 예제에서는 조건부 블록을 나타내는 식을 만드는 방법을 보여 줍니다.

// Add the following directive to the file:
// using System.Linq.Expressions;
bool test = true;

// This expression represents the conditional block.
Expression ifThenExpr = Expression.IfThen(
    Expression.Constant(test),
    Expression.Call(
        null,
        typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
        Expression.Constant("The condition is true.")
       )
);

// The following statement first creates an expression tree,
// then compiles it, and then runs it.
Expression.Lambda<Action>(ifThenExpr).Compile()();

// This code example produces the following output:
//
// The condition is true.
' Add the following directive to the file:
' Imports System.Linq.Expressions

Dim test As Boolean = True

' This expression represents the conditional block.
Dim ifThenExpr As Expression = Expression.IfThen(
     Expression.Constant(test),
     Expression.Call(
         Nothing,
         GetType(Console).GetMethod("WriteLine", New Type() {GetType(String)}),
         Expression.Constant("The condition is true.")
     )
)

' The following statement first creates an expression tree,
' then compiles it, and then runs it.
Expression.Lambda(Of Action)(ifThenExpr).Compile()()

' This code example produces the following output:
'
' The condition is true.

적용 대상