Expression.Switch 메서드

정의

SwitchExpression 문을 나타내는 switch을 만듭니다.

오버로드

Switch(Type, Expression, Expression, MethodInfo, SwitchCase[])

기본 사례가 있는 SwitchExpression 문을 나타내는 switch을 만듭니다.

Switch(Expression, SwitchCase[])

기본 사례가 없는 SwitchExpression 문을 나타내는 switch을 만듭니다.

Switch(Expression, Expression, SwitchCase[])

기본 사례가 있는 SwitchExpression 문을 나타내는 switch을 만듭니다.

Switch(Expression, Expression, MethodInfo, IEnumerable<SwitchCase>)

기본 사례가 있는 SwitchExpression 문을 나타내는 switch을 만듭니다.

Switch(Expression, Expression, MethodInfo, SwitchCase[])

기본 사례가 있는 SwitchExpression 문을 나타내는 switch을 만듭니다.

Switch(Type, Expression, Expression, MethodInfo, IEnumerable<SwitchCase>)

기본 사례가 있는 SwitchExpression 문을 나타내는 switch을 만듭니다.

Switch(Type, Expression, Expression, MethodInfo, SwitchCase[])

Source:
SwitchExpression.cs
Source:
SwitchExpression.cs
Source:
SwitchExpression.cs

기본 사례가 있는 SwitchExpression 문을 나타내는 switch을 만듭니다.

public:
 static System::Linq::Expressions::SwitchExpression ^ Switch(Type ^ type, System::Linq::Expressions::Expression ^ switchValue, System::Linq::Expressions::Expression ^ defaultBody, System::Reflection::MethodInfo ^ comparison, ... cli::array <System::Linq::Expressions::SwitchCase ^> ^ cases);
public static System.Linq.Expressions.SwitchExpression Switch (Type type, System.Linq.Expressions.Expression switchValue, System.Linq.Expressions.Expression defaultBody, System.Reflection.MethodInfo comparison, params System.Linq.Expressions.SwitchCase[] cases);
public static System.Linq.Expressions.SwitchExpression Switch (Type? type, System.Linq.Expressions.Expression switchValue, System.Linq.Expressions.Expression? defaultBody, System.Reflection.MethodInfo? comparison, params System.Linq.Expressions.SwitchCase[]? cases);
static member Switch : Type * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Reflection.MethodInfo * System.Linq.Expressions.SwitchCase[] -> System.Linq.Expressions.SwitchExpression
Public Shared Function Switch (type As Type, switchValue As Expression, defaultBody As Expression, comparison As MethodInfo, ParamArray cases As SwitchCase()) As SwitchExpression

매개 변수

type
Type

switch의 결과 형식입니다.

switchValue
Expression

각 사례에 대해 테스트할 값입니다.

defaultBody
Expression

switchValue로 일치하는 사례가 없는 경우 switch의 결과입니다.

comparison
MethodInfo

사용할 같음 비교 메서드입니다.

cases
SwitchCase[]

이 switch 식의 사례 집합입니다.

반환

만든 SwitchExpression입니다.

적용 대상

Switch(Expression, SwitchCase[])

Source:
SwitchExpression.cs
Source:
SwitchExpression.cs
Source:
SwitchExpression.cs

기본 사례가 없는 SwitchExpression 문을 나타내는 switch을 만듭니다.

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

매개 변수

switchValue
Expression

각 사례에 대해 테스트할 값입니다.

cases
SwitchCase[]

이 switch 식의 사례 집합입니다.

반환

만든 SwitchExpression입니다.

예제

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

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

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

// This expression represents a switch statement
// without a default case.
SwitchExpression switchExpr =
    Expression.Switch(
        switchValue,
        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:
//
// Second
' Add the following directive to the file:
' Imports System.Linq.Expressions

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

' This expression represents a switch statement 
' without a default case.
Dim switchExpr As SwitchExpression =
Expression.Switch(
    switchValue,
    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:
'
' Second

설명

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

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

switchValue 가 사례와 일치하지 않으면 예외가 throw되지 않습니다.

적용 대상

Switch(Expression, Expression, SwitchCase[])

Source:
SwitchExpression.cs
Source:
SwitchExpression.cs
Source:
SwitchExpression.cs

기본 사례가 있는 SwitchExpression 문을 나타내는 switch을 만듭니다.

public:
 static System::Linq::Expressions::SwitchExpression ^ Switch(System::Linq::Expressions::Expression ^ switchValue, System::Linq::Expressions::Expression ^ defaultBody, ... cli::array <System::Linq::Expressions::SwitchCase ^> ^ cases);
public static System.Linq.Expressions.SwitchExpression Switch (System.Linq.Expressions.Expression switchValue, System.Linq.Expressions.Expression defaultBody, params System.Linq.Expressions.SwitchCase[] cases);
public static System.Linq.Expressions.SwitchExpression Switch (System.Linq.Expressions.Expression switchValue, System.Linq.Expressions.Expression? defaultBody, params System.Linq.Expressions.SwitchCase[]? cases);
static member Switch : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.SwitchCase[] -> System.Linq.Expressions.SwitchExpression
Public Shared Function Switch (switchValue As Expression, defaultBody As Expression, ParamArray cases As SwitchCase()) As SwitchExpression

매개 변수

switchValue
Expression

각 사례에 대해 테스트할 값입니다.

defaultBody
Expression

switchValue로 일치하는 사례가 없는 경우 switch의 결과입니다.

cases
SwitchCase[]

이 switch 식의 사례 집합입니다.

반환

만든 SwitchExpression입니다.

예제

다음 예제에서는 기본 사례가 있는 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 문이 있습니다. 즉, 한 사례 레이블에서 다른 사례 레이블로의 암시적 대체가 없습니다.

switchValue 가 사례와 일치하지 않으면 에서 나타내는 defaultBody 기본 사례가 실행됩니다.

적용 대상

Switch(Expression, Expression, MethodInfo, IEnumerable<SwitchCase>)

Source:
SwitchExpression.cs
Source:
SwitchExpression.cs
Source:
SwitchExpression.cs

기본 사례가 있는 SwitchExpression 문을 나타내는 switch을 만듭니다.

public:
 static System::Linq::Expressions::SwitchExpression ^ Switch(System::Linq::Expressions::Expression ^ switchValue, System::Linq::Expressions::Expression ^ defaultBody, System::Reflection::MethodInfo ^ comparison, System::Collections::Generic::IEnumerable<System::Linq::Expressions::SwitchCase ^> ^ cases);
public static System.Linq.Expressions.SwitchExpression Switch (System.Linq.Expressions.Expression switchValue, System.Linq.Expressions.Expression defaultBody, System.Reflection.MethodInfo comparison, System.Collections.Generic.IEnumerable<System.Linq.Expressions.SwitchCase> cases);
public static System.Linq.Expressions.SwitchExpression Switch (System.Linq.Expressions.Expression switchValue, System.Linq.Expressions.Expression? defaultBody, System.Reflection.MethodInfo? comparison, System.Collections.Generic.IEnumerable<System.Linq.Expressions.SwitchCase>? cases);
static member Switch : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Reflection.MethodInfo * seq<System.Linq.Expressions.SwitchCase> -> System.Linq.Expressions.SwitchExpression
Public Shared Function Switch (switchValue As Expression, defaultBody As Expression, comparison As MethodInfo, cases As IEnumerable(Of SwitchCase)) As SwitchExpression

매개 변수

switchValue
Expression

각 사례에 대해 테스트할 값입니다.

defaultBody
Expression

switchValue로 일치하는 사례가 없는 경우 switch의 결과입니다.

comparison
MethodInfo

사용할 같음 비교 메서드입니다.

cases
IEnumerable<SwitchCase>

이 switch 식의 사례 집합입니다.

반환

만든 SwitchExpression입니다.

적용 대상

Switch(Expression, Expression, MethodInfo, SwitchCase[])

Source:
SwitchExpression.cs
Source:
SwitchExpression.cs
Source:
SwitchExpression.cs

기본 사례가 있는 SwitchExpression 문을 나타내는 switch을 만듭니다.

public:
 static System::Linq::Expressions::SwitchExpression ^ Switch(System::Linq::Expressions::Expression ^ switchValue, System::Linq::Expressions::Expression ^ defaultBody, System::Reflection::MethodInfo ^ comparison, ... cli::array <System::Linq::Expressions::SwitchCase ^> ^ cases);
public static System.Linq.Expressions.SwitchExpression Switch (System.Linq.Expressions.Expression switchValue, System.Linq.Expressions.Expression defaultBody, System.Reflection.MethodInfo comparison, params System.Linq.Expressions.SwitchCase[] cases);
public static System.Linq.Expressions.SwitchExpression Switch (System.Linq.Expressions.Expression switchValue, System.Linq.Expressions.Expression? defaultBody, System.Reflection.MethodInfo? comparison, params System.Linq.Expressions.SwitchCase[]? cases);
static member Switch : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Reflection.MethodInfo * System.Linq.Expressions.SwitchCase[] -> System.Linq.Expressions.SwitchExpression
Public Shared Function Switch (switchValue As Expression, defaultBody As Expression, comparison As MethodInfo, ParamArray cases As SwitchCase()) As SwitchExpression

매개 변수

switchValue
Expression

각 사례에 대해 테스트할 값입니다.

defaultBody
Expression

switchValue로 일치하는 사례가 없는 경우 switch의 결과입니다.

comparison
MethodInfo

사용할 같음 비교 메서드입니다.

cases
SwitchCase[]

이 switch 식의 사례 집합입니다.

반환

만든 SwitchExpression입니다.

적용 대상

Switch(Type, Expression, Expression, MethodInfo, IEnumerable<SwitchCase>)

Source:
SwitchExpression.cs
Source:
SwitchExpression.cs
Source:
SwitchExpression.cs

기본 사례가 있는 SwitchExpression 문을 나타내는 switch을 만듭니다.

public:
 static System::Linq::Expressions::SwitchExpression ^ Switch(Type ^ type, System::Linq::Expressions::Expression ^ switchValue, System::Linq::Expressions::Expression ^ defaultBody, System::Reflection::MethodInfo ^ comparison, System::Collections::Generic::IEnumerable<System::Linq::Expressions::SwitchCase ^> ^ cases);
public static System.Linq.Expressions.SwitchExpression Switch (Type type, System.Linq.Expressions.Expression switchValue, System.Linq.Expressions.Expression defaultBody, System.Reflection.MethodInfo comparison, System.Collections.Generic.IEnumerable<System.Linq.Expressions.SwitchCase> cases);
public static System.Linq.Expressions.SwitchExpression Switch (Type? type, System.Linq.Expressions.Expression switchValue, System.Linq.Expressions.Expression? defaultBody, System.Reflection.MethodInfo? comparison, System.Collections.Generic.IEnumerable<System.Linq.Expressions.SwitchCase>? cases);
static member Switch : Type * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Reflection.MethodInfo * seq<System.Linq.Expressions.SwitchCase> -> System.Linq.Expressions.SwitchExpression
Public Shared Function Switch (type As Type, switchValue As Expression, defaultBody As Expression, comparison As MethodInfo, cases As IEnumerable(Of SwitchCase)) As SwitchExpression

매개 변수

type
Type

switch의 결과 형식입니다.

switchValue
Expression

각 사례에 대해 테스트할 값입니다.

defaultBody
Expression

switchValue로 일치하는 사례가 없는 경우 switch의 결과입니다.

comparison
MethodInfo

사용할 같음 비교 메서드입니다.

cases
IEnumerable<SwitchCase>

이 switch 식의 사례 집합입니다.

반환

만든 SwitchExpression입니다.

적용 대상