SwitchExpression Sınıf

Tanım

denetimi öğesine geçirerek birden çok seçimi işleyen bir denetim SwitchCaseifadesini temsil eder.

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
Devralma
SwitchExpression

Örnekler

Aşağıdaki örnek, yöntemini kullanarak varsayılan büyük/küçük harfe sahip bir switch deyimini temsil eden bir ifadenin Switch nasıl oluşturulacağını gösterir.

// 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

Özellikler

CanReduce

Düğümün daha basit bir düğüme indirgenebileceğini gösterir. Bu true değerini döndürürse, azaltılmış formu oluşturmak için Reduce() çağrılabilir.

(Devralındığı yer: Expression)
Cases

Anahtar için nesne koleksiyonunu SwitchCase alır.

Comparison

Varsa, eşitlik karşılaştırma yöntemini alır.

DefaultBody

Anahtarın testini alır.

NodeType

Bu İfadenin düğüm türünü döndürür. Bu yöntem geçersiz kılınırken uzantı düğümleri döndürülmelidir Extension .

SwitchValue

Anahtarın testini alır.

Type

Bunu Expression temsil eden ifadenin statik türünü alır.

Yöntemler

Accept(ExpressionVisitor)

Bu düğüm türü için belirli bir ziyaret yöntemine gönderilir. Örneğin, MethodCallExpression öğesini çağırır VisitMethodCall(MethodCallExpression).

(Devralındığı yer: Expression)
Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetType()

Type Geçerli örneğini alır.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

(Devralındığı yer: Object)
Reduce()

Bu düğümü daha basit bir ifadeye küçültür. CanReduce true döndürürse, bu geçerli bir ifade döndürmelidir. Bu yöntem, azaltılması gereken başka bir düğüm döndürebilir.

(Devralındığı yer: Expression)
ReduceAndCheck()

Bu düğümü daha basit bir ifadeye küçültür. CanReduce true döndürürse, bu geçerli bir ifade döndürmelidir. Bu yöntem, azaltılması gereken başka bir düğüm döndürebilir.

(Devralındığı yer: Expression)
ReduceExtensions()

İfadeyi bilinen bir düğüm türüne (Uzantı düğümü değil) küçültür veya zaten bilinen bir türse yalnızca ifadeyi döndürür.

(Devralındığı yer: Expression)
ToString()

öğesinin metinsel gösterimini Expressiondöndürür.

(Devralındığı yer: Expression)
Update(Expression, IEnumerable<SwitchCase>, Expression)

Bunun gibi, ancak sağlanan alt öğeleri kullanarak yeni bir ifade oluşturur. Tüm alt öğeler aynıysa bu ifadeyi döndürür.

VisitChildren(ExpressionVisitor)

Düğümü azaltır ve ardından azaltılmış ifadede ziyaretçi temsilcisini çağırır. Düğüm azaltılabilir değilse yöntemi bir özel durum oluşturur.

(Devralındığı yer: Expression)

Şunlara uygulanır