SwitchExpression 클래스

정의

제어를 SwitchCase로 전달하여 다중 선택을 처리하는 제어 식을 나타냅니다.

public ref class SwitchExpression sealed : System::Linq::Expressions::Expression
public sealed class SwitchExpression : System.Linq.Expressions.Expression
type SwitchExpression = class
    inherit Expression
Public NotInheritable Class SwitchExpression
Inherits Expression
상속
SwitchExpression

예제

다음 예제에서는 메서드를 사용하여 Switch 기본 사례가 있는 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

속성

CanReduce

노드를 더 단순한 노드로 줄일 수 있는지 나타냅니다. true를 반환하면 Reduce()를 호출하여 축소된 형식을 만들 수 있습니다.

(다음에서 상속됨 Expression)
Cases

switch에 대한 SwitchCase 개체 컬렉션을 가져옵니다.

Comparison

같음 비교 메서드를 가져옵니다(있는 경우).

DefaultBody

switch에 대한 테스트를 가져옵니다.

NodeType

이 식의 노드 형식을 반환합니다. 확장 노드는 이 메서드를 재정의할 때 Extension을 반환해야 합니다.

SwitchValue

switch에 대한 테스트를 가져옵니다.

Type

Expression이 나타내는 식의 정적 형식을 가져옵니다.

메서드

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, IEnumerable<SwitchCase>, Expression)

제공된 자식을 사용하여 이 식과 같은 새 식을 만듭니다. 모든 자식이 같으면 이 식을 반환합니다.

VisitChildren(ExpressionVisitor)

노드를 줄인 다음 줄인 식에서 방문자 대리자를 호출합니다. 이 메서드는 노드를 줄일 수 없으면 예외를 throw합니다.

(다음에서 상속됨 Expression)

적용 대상