Expression.Switch 메서드

정의

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

오버로드

Name Description
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
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

스위치의 결과 형식입니다.

switchValue
Expression

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

defaultBody
Expression

케이스와 일치하지 않는 경우 switchValue 스위치의 결과입니다.

comparison
MethodInfo

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

cases
SwitchCase[]

이 스위치 식의 사례 집합입니다.

반품

만든 SwitchExpression.

적용 대상

Switch(Expression, SwitchCase[])

Source:
SwitchExpression.cs
Source:
SwitchExpression.cs
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[]

이 스위치 식의 사례 집합입니다.

반품

만든 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

설명

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

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

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

적용 대상

Switch(Expression, Expression, SwitchCase[])

Source:
SwitchExpression.cs
Source:
SwitchExpression.cs
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 스위치의 결과입니다.

cases
SwitchCase[]

이 스위치 식의 사례 집합입니다.

반품

만든 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

설명

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

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

switchValue 사례와 일치하지 않으면 표시되는 defaultBody 기본 사례가 실행됩니다.

적용 대상

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

Source:
SwitchExpression.cs
Source:
SwitchExpression.cs
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 스위치의 결과입니다.

comparison
MethodInfo

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

cases
IEnumerable<SwitchCase>

이 스위치 식의 사례 집합입니다.

반품

만든 SwitchExpression.

적용 대상

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

Source:
SwitchExpression.cs
Source:
SwitchExpression.cs
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 스위치의 결과입니다.

comparison
MethodInfo

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

cases
SwitchCase[]

이 스위치 식의 사례 집합입니다.

반품

만든 SwitchExpression.

적용 대상

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

Source:
SwitchExpression.cs
Source:
SwitchExpression.cs
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

스위치의 결과 형식입니다.

switchValue
Expression

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

defaultBody
Expression

케이스와 일치하지 않는 경우 switchValue 스위치의 결과입니다.

comparison
MethodInfo

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

cases
IEnumerable<SwitchCase>

이 스위치 식의 사례 집합입니다.

반품

만든 SwitchExpression.

적용 대상