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

속성

Name Description
CanReduce

노드를 더 간단한 노드로 줄일 수 있음을 나타냅니다. true를 반환하면 Reduce()를 호출하여 축소된 폼을 생성할 수 있습니다.

(다음에서 상속됨 Expression)
Cases

스위치의 개체 컬렉션을 SwitchCase 가져옵니다.

Comparison

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

DefaultBody

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

NodeType

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

SwitchValue

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

Type

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

메서드

Name Description
Accept(ExpressionVisitor)

이 노드 형식에 대한 특정 방문 메서드로 디스패치합니다. 예를 들어 . 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)

적용 대상