Expression.Switch Expression.Switch Expression.Switch Expression.Switch Method

定義

SwitchExpression ステートメントを表す switch を作成します。Creates a SwitchExpression that represents a switch statement.

オーバーロード

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

既定のケースがある SwitchExpression ステートメントを表す switch を作成します。Creates a SwitchExpression that represents a switch statement that has a default case.

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

既定のケースのない SwitchExpression ステートメントを表す switch を作成します。Creates a SwitchExpression that represents a switch statement without a default case.

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

既定のケースがある SwitchExpression ステートメントを表す switch を作成します。Creates a SwitchExpression that represents a switch statement that has a default case.

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

既定のケースがある SwitchExpression ステートメントを表す switch を作成します。Creates a SwitchExpression that represents a switch statement that has a default case.

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

既定のケースがある SwitchExpression ステートメントを表す switch を作成します。Creates a SwitchExpression that represents a switch statement that has a default case.

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

既定のケースがある SwitchExpression ステートメントを表す switch を作成します。Creates a SwitchExpression that represents a switch statement that has a default case.

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

既定のケースがある SwitchExpression ステートメントを表す switch を作成します。Creates a SwitchExpression that represents a switch statement that has a default case.

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);
static member Switch : Type * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Reflection.MethodInfo * System.Linq.Expressions.SwitchCase[] -> System.Linq.Expressions.SwitchExpression

パラメーター

type
Type Type Type Type

switch の結果の型。The result type of the switch.

switchValue
Expression Expression Expression Expression

各ケースに対してテストする値。The value to be tested against each case.

defaultBody
Expression Expression Expression Expression

switchValue がいずれのケースとも一致しない場合の switch の結果。The result of the switch if switchValue does not match any of the cases.

comparison
MethodInfo MethodInfo MethodInfo MethodInfo

使用する等値比較メソッド。The equality comparison method to use.

cases
SwitchCase[]

この switch 式に対するケースのセット。The set of cases for this switch expression.

戻り値

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

既定のケースのない SwitchExpression ステートメントを表す switch を作成します。Creates a SwitchExpression that represents a switch statement without a default case.

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);
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 Expression Expression Expression

各ケースに対してテストする値。The value to be tested against each case.

cases
SwitchCase[]

この switch 式に対するケースのセット。The set of cases for this switch expression.

戻り値

次の例では、既定のケースのないスイッチ ステートメントを表す式を作成する方法を示します。The following example demonstrates how to create an expression that represents a switch statement without a default case.

// 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します。All SwitchCase objects in a SwitchExpression object must have the same type, unless the SwitchExpression has the type void.

SwitchCaseオブジェクトが暗黙的なbreakステートメントで、暗黙的なフォール スルー 1 つの case ラベルから間がないことを意味します。Each SwitchCase object has an implicit break statement, which means that there is no implicit fall through from one case label to another.

場合switchValueいずれかと一致しない場合にの例外はスローされません。If switchValue does not match any of the cases, no exception is thrown.

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

既定のケースがある SwitchExpression ステートメントを表す switch を作成します。Creates a SwitchExpression that represents a switch statement that has a default case.

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);
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 Expression Expression Expression

各ケースに対してテストする値。The value to be tested against each case.

defaultBody
Expression Expression Expression Expression

switchValue がいずれのケースとも一致しない場合の switch の結果。The result of the switch if switchValue does not match any of the cases.

cases
SwitchCase[]

この switch 式に対するケースのセット。The set of cases for this switch expression.

戻り値

次の例では、既定のケースが switch ステートメントを表す式を作成する方法を示します。The following example demonstrates how to create an expression that represents a switch statement that has a default case.

// 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します。All SwitchCase objects in a SwitchExpression object must have the same type, unless the SwitchExpression has the type void.

SwitchCaseオブジェクトが暗黙的なbreakステートメントで、暗黙的なフォール スルー 1 つの case ラベルから間がないことを意味します。Each SwitchCase object has an implicit break statement, which means that there is no implicit fall through from one case label to another.

場合switchValueによって表される既定のケースの場合のいずれかと一致しないdefaultBodyを実行します。If switchValue does not match any of the cases, the default case represented by defaultBody is run.

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

既定のケースがある SwitchExpression ステートメントを表す switch を作成します。Creates a SwitchExpression that represents a switch statement that has a default case.

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

各ケースに対してテストする値。The value to be tested against each case.

defaultBody
Expression Expression Expression Expression

switchValue がいずれのケースとも一致しない場合の switch の結果。The result of the switch if switchValue does not match any of the cases.

comparison
MethodInfo MethodInfo MethodInfo MethodInfo

使用する等値比較メソッド。The equality comparison method to use.

cases
IEnumerable<SwitchCase>

この switch 式に対するケースのセット。The set of cases for this switch expression.

戻り値

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

既定のケースがある SwitchExpression ステートメントを表す switch を作成します。Creates a SwitchExpression that represents a switch statement that has a default case.

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);
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 Expression Expression Expression

各ケースに対してテストする値。The value to be tested against each case.

defaultBody
Expression Expression Expression Expression

switchValue がいずれのケースとも一致しない場合の switch の結果。The result of the switch if switchValue does not match any of the cases.

comparison
MethodInfo MethodInfo MethodInfo MethodInfo

使用する等値比較メソッド。The equality comparison method to use.

cases
SwitchCase[]

この switch 式に対するケースのセット。The set of cases for this switch expression.

戻り値

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

既定のケースがある SwitchExpression ステートメントを表す switch を作成します。Creates a SwitchExpression that represents a switch statement that has a default case.

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

パラメーター

type
Type Type Type Type

switch の結果の型。The result type of the switch.

switchValue
Expression Expression Expression Expression

各ケースに対してテストする値。The value to be tested against each case.

defaultBody
Expression Expression Expression Expression

switchValue がいずれのケースとも一致しない場合の switch の結果。The result of the switch if switchValue does not match any of the cases.

comparison
MethodInfo MethodInfo MethodInfo MethodInfo

使用する等値比較メソッド。The equality comparison method to use.

cases
IEnumerable<SwitchCase>

この switch 式に対するケースのセット。The set of cases for this switch expression.

戻り値

適用対象