Expression.Switch Yöntem

Tanım

Deyimi SwitchExpression temsil eden bir switch oluşturur.

Aşırı Yüklemeler

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

Varsayılan büyük SwitchExpression /küçük harfe sahip bir switch deyimi temsil eden bir oluşturur.

Switch(Expression, SwitchCase[])

Varsayılan servis SwitchExpression talebi olmayan bir switch deyimi temsil eden bir oluşturur.

Switch(Expression, Expression, SwitchCase[])

Varsayılan büyük SwitchExpression /küçük harfe sahip bir switch deyimi temsil eden bir oluşturur.

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

Varsayılan büyük SwitchExpression /küçük harfe sahip bir switch deyimi temsil eden bir oluşturur.

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

Varsayılan büyük SwitchExpression /küçük harfe sahip bir switch deyimi temsil eden bir oluşturur.

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

Varsayılan büyük SwitchExpression /küçük harfe sahip bir switch deyimi temsil eden bir oluşturur.

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

Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs

Varsayılan büyük SwitchExpression /küçük harfe sahip bir switch deyimi temsil eden bir oluşturur.

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

Parametreler

type
Type

Anahtarın sonuç türü.

switchValue
Expression

Her durumda test edilecek değer.

defaultBody
Expression

Herhangi bir durumla eşleşmiyorsa anahtarın switchValue sonucu.

comparison
MethodInfo

Kullanılacak eşitlik karşılaştırma yöntemi.

cases
SwitchCase[]

Bu anahtar ifadesi için servis talebi kümesi.

Döndürülenler

Oluşturulan SwitchExpression.

Şunlara uygulanır

Switch(Expression, SwitchCase[])

Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs

Varsayılan servis SwitchExpression talebi olmayan bir switch deyimi temsil eden bir oluşturur.

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

Parametreler

switchValue
Expression

Her durumda test edilecek değer.

cases
SwitchCase[]

Bu anahtar ifadesi için servis talebi kümesi.

Döndürülenler

Oluşturulan SwitchExpression.

Örnekler

Aşağıdaki örnekte, varsayılan büyük/küçük harf olmadan switch deyimini temsil eden bir ifadenin nasıl oluşturulacağı gösterilmektedir.

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

Açıklamalar

türüne sahip olmadığı sürece, nesnedeki SwitchCase tüm SwitchExpression nesneler aynı türe SwitchExpressionvoidsahip olmalıdır.

Her SwitchCase nesnenin örtük break bir deyimi vardır, yani bir büyük/küçük harf etiketinden diğerine örtük bir düşüş yoktur.

Herhangi switchValue bir durumla eşleşmiyorsa, hiçbir özel durum oluşturulur.

Şunlara uygulanır

Switch(Expression, Expression, SwitchCase[])

Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs

Varsayılan büyük SwitchExpression /küçük harfe sahip bir switch deyimi temsil eden bir oluşturur.

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

Parametreler

switchValue
Expression

Her durumda test edilecek değer.

defaultBody
Expression

Herhangi bir durumla eşleşmiyorsa anahtarın switchValue sonucu.

cases
SwitchCase[]

Bu anahtar ifadesi için servis talebi kümesi.

Döndürülenler

Oluşturulan SwitchExpression.

Örnekler

Aşağıdaki örnekte, varsayılan büyük/küçük harfe sahip bir switch deyimini temsil eden bir ifadenin nasıl oluşturulacağı gösterilmektedir.

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

Açıklamalar

türüne sahip olmadığı sürece, nesnedeki SwitchCase tüm SwitchExpression nesneler aynı türe SwitchExpressionvoidsahip olmalıdır.

Her SwitchCase nesnenin örtük break bir deyimi vardır, yani bir büyük/küçük harf etiketinden diğerine örtük bir düşüş yoktur.

Hiçbir switchValue servis talebiyle eşleşmiyorsa, tarafından defaultBody temsil edilen varsayılan servis talebi çalıştırılır.

Şunlara uygulanır

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

Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs

Varsayılan büyük SwitchExpression /küçük harfe sahip bir switch deyimi temsil eden bir oluşturur.

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

Parametreler

switchValue
Expression

Her durumda test edilecek değer.

defaultBody
Expression

Herhangi bir durumla eşleşmiyorsa anahtarın switchValue sonucu.

comparison
MethodInfo

Kullanılacak eşitlik karşılaştırma yöntemi.

cases
IEnumerable<SwitchCase>

Bu anahtar ifadesi için servis talebi kümesi.

Döndürülenler

Oluşturulan SwitchExpression.

Şunlara uygulanır

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

Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs

Varsayılan büyük SwitchExpression /küçük harfe sahip bir switch deyimi temsil eden bir oluşturur.

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

Parametreler

switchValue
Expression

Her durumda test edilecek değer.

defaultBody
Expression

Herhangi bir durumla eşleşmiyorsa anahtarın switchValue sonucu.

comparison
MethodInfo

Kullanılacak eşitlik karşılaştırma yöntemi.

cases
SwitchCase[]

Bu anahtar ifadesi için servis talebi kümesi.

Döndürülenler

Oluşturulan SwitchExpression.

Şunlara uygulanır

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

Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs
Kaynak:
SwitchExpression.cs

Varsayılan büyük SwitchExpression /küçük harfe sahip bir switch deyimi temsil eden bir oluşturur.

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

Parametreler

type
Type

Anahtarın sonuç türü.

switchValue
Expression

Her durumda test edilecek değer.

defaultBody
Expression

Herhangi bir durumla eşleşmiyorsa anahtarın switchValue sonucu.

comparison
MethodInfo

Kullanılacak eşitlik karşılaştırma yöntemi.

cases
IEnumerable<SwitchCase>

Bu anahtar ifadesi için servis talebi kümesi.

Döndürülenler

Oluşturulan SwitchExpression.

Şunlara uygulanır