Expression.SwitchCase 메서드

정의

SwitchCase 개체에 사용할 SwitchExpression 개체를 만듭니다.

오버로드

SwitchCase(Expression, Expression[])

SwitchCase에 사용할 SwitchExpression를 만듭니다.

SwitchCase(Expression, IEnumerable<Expression>)

SwitchCase 개체에 사용할 SwitchExpression 개체를 만듭니다.

SwitchCase(Expression, Expression[])

Source:
SwitchCase.cs
Source:
SwitchCase.cs
Source:
SwitchCase.cs

SwitchCase에 사용할 SwitchExpression를 만듭니다.

public:
 static System::Linq::Expressions::SwitchCase ^ SwitchCase(System::Linq::Expressions::Expression ^ body, ... cli::array <System::Linq::Expressions::Expression ^> ^ testValues);
public static System.Linq.Expressions.SwitchCase SwitchCase (System.Linq.Expressions.Expression body, params System.Linq.Expressions.Expression[] testValues);
static member SwitchCase : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.SwitchCase
Public Shared Function SwitchCase (body As Expression, ParamArray testValues As Expression()) As SwitchCase

매개 변수

body
Expression

case의 본문입니다.

testValues
Expression[]

case의 테스트 값입니다.

반환

만든 SwitchCase입니다.

적용 대상

SwitchCase(Expression, IEnumerable<Expression>)

Source:
SwitchCase.cs
Source:
SwitchCase.cs
Source:
SwitchCase.cs

SwitchCase 개체에 사용할 SwitchExpression 개체를 만듭니다.

public:
 static System::Linq::Expressions::SwitchCase ^ SwitchCase(System::Linq::Expressions::Expression ^ body, System::Collections::Generic::IEnumerable<System::Linq::Expressions::Expression ^> ^ testValues);
public static System.Linq.Expressions.SwitchCase SwitchCase (System.Linq.Expressions.Expression body, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> testValues);
static member SwitchCase : System.Linq.Expressions.Expression * seq<System.Linq.Expressions.Expression> -> System.Linq.Expressions.SwitchCase
Public Shared Function SwitchCase (body As Expression, testValues As IEnumerable(Of Expression)) As SwitchCase

매개 변수

body
Expression

case의 본문입니다.

testValues
IEnumerable<Expression>

case의 테스트 값입니다.

반환

만든 SwitchCase입니다.

예제

다음 예제에서는 기본 사례가 있는 switch 문을 나타내는 식을 만드는 방법을 보여 줍니다.

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

// An expression that represents the switch value.
ConstantExpression switchValue = Expression.Constant(3);

// This expression represents a switch statement
// that has a default case.
SwitchExpression switchExpr =
    Expression.Switch(
        switchValue,
        Expression.Call(
                    null,
                    typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
                    Expression.Constant("Default")
                ),
        new SwitchCase[] {
            Expression.SwitchCase(
                Expression.Call(
                    null,
                    typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
                    Expression.Constant("First")
                ),
                Expression.Constant(1)
            ),
            Expression.SwitchCase(
                Expression.Call(
                    null,
                    typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
                    Expression.Constant("Second")
                ),
                Expression.Constant(2)
            )
        }
    );

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

// This code example produces the following output:
//
// Default
' Add the following directive to the file:
' Imports System.Linq.Expressions

' An expression that represents the switch value.
Dim switchValue As ConstantExpression = Expression.Constant(3)

' This expression represents a switch statement 
' that has a default case.
Dim switchExpr As SwitchExpression =
Expression.Switch(
    switchValue,
    Expression.Call(
                Nothing,
                GetType(Console).GetMethod("WriteLine", New Type() {GetType(String)}),
                Expression.Constant("Default")
            ),
    New SwitchCase() {
        Expression.SwitchCase(
            Expression.Call(
                Nothing,
                GetType(Console).GetMethod("WriteLine", New Type() {GetType(String)}),
                Expression.Constant("First")
            ),
            Expression.Constant(1)
        ),
        Expression.SwitchCase(
            Expression.Call(
                Nothing,
                GetType(Console).GetMethod("WriteLine", New Type() {GetType(String)}),
                Expression.Constant("Second")
            ),
            Expression.Constant(2)
        )
    }
)

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

' This code example produces the following output:
'
' Default

설명

에 형식이 SwitchExpression 없는 한 SwitchExpression 개체의 모든 SwitchCase 개체에는 동일한 형식void이 있어야 합니다.

SwitchCase 개체에는 암시적 break 문이 있습니다. 즉, 한 사례 레이블에서 다른 사례 레이블로의 암시적 대체가 없습니다.

적용 대상