SwitchExpression SwitchExpression SwitchExpression SwitchExpression Class

定義

SwitchCase に制御を渡すことによって複数の選択内容を処理する制御式を表します。Represents a control expression that handles multiple selections by passing control to 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
継承
SwitchExpressionSwitchExpressionSwitchExpressionSwitchExpression

次の例を使用して既定のケースを持つ switch ステートメントを表す式を作成する方法、Switchメソッド。The following example demonstrates how to create an expression that represents a switch statement that has a default case by using the Switch method.

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

ノードをより単純なノードに変形できることを示します。Indicates that the node can be reduced to a simpler node. これが true を返す場合、Reduce() を呼び出して単純化された形式を生成できます。If this returns true, Reduce() can be called to produce the reduced form.

(Inherited from Expression)
Cases Cases Cases Cases

switch に対応する SwitchCase オブジェクトのコレクションを取得します。Gets the collection of SwitchCase objects for the switch.

Comparison Comparison Comparison Comparison

等価比較メソッドを取得します (存在する場合)。Gets the equality comparison method, if any.

DefaultBody DefaultBody DefaultBody DefaultBody

switch のテストを取得します。Gets the test for the switch.

NodeType NodeType NodeType NodeType

この式のノード型を返します。Returns the node type of this Expression. 拡張ノードは、このメソッドをオーバーライドする際に Extension を返す必要があります。Extension nodes should return Extension when overriding this method.

SwitchValue SwitchValue SwitchValue SwitchValue

switch のテストを取得します。Gets the test for the switch.

Type Type Type Type

この Expression が表す式の静的な型を取得します。Gets the static type of the expression that this Expression represents.

メソッド

Accept(ExpressionVisitor) Accept(ExpressionVisitor) Accept(ExpressionVisitor) Accept(ExpressionVisitor)

このノード型の特定の Visit メソッドにデスパッチします。Dispatches to the specific visit method for this node type. たとえば、MethodCallExpressionVisitMethodCall(MethodCallExpression) を呼び出します。For example, MethodCallExpression calls the VisitMethodCall(MethodCallExpression).

(Inherited from Expression)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

指定したオブジェクトが、現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
Reduce() Reduce() Reduce() Reduce()

このノードをより単純な式に変形します。Reduces this node to a simpler expression. CanReduce が true を返す場合、これは有効な式を返します。If CanReduce returns true, this should return a valid expression. このメソッドは、それ自体も単純化する必要がある別のノードを返す場合があります。This method can return another node which itself must be reduced.

(Inherited from Expression)
ReduceAndCheck() ReduceAndCheck() ReduceAndCheck() ReduceAndCheck()

このノードをより単純な式に変形します。Reduces this node to a simpler expression. CanReduce が true を返す場合、これは有効な式を返します。If CanReduce returns true, this should return a valid expression. このメソッドは、それ自体も単純化する必要がある別のノードを返す場合があります。This method can return another node which itself must be reduced.

(Inherited from Expression)
ReduceExtensions() ReduceExtensions() ReduceExtensions() ReduceExtensions()

式を既知のノード型 (拡張ノードではない型) に単純化し、それが既に既知の型である場合は単に式を返します。Reduces the expression to a known node type (that is not an Extension node) or just returns the expression if it is already a known type.

(Inherited from Expression)
ToString() ToString() ToString() ToString()

Expression のテキスト表現を返します。Returns a textual representation of the Expression.

(Inherited from Expression)
Update(Expression, IEnumerable<SwitchCase>, Expression) Update(Expression, IEnumerable<SwitchCase>, Expression) Update(Expression, IEnumerable<SwitchCase>, Expression) Update(Expression, IEnumerable<SwitchCase>, Expression)

この式に似た新しい式を作成しますが、指定された子を使用します。Creates a new expression that is like this one, but using the supplied children. すべての子が同じであれば、この式が返されます。If all of the children are the same, it will return this expression.

VisitChildren(ExpressionVisitor) VisitChildren(ExpressionVisitor) VisitChildren(ExpressionVisitor) VisitChildren(ExpressionVisitor)

ノードを単純化し、単純化された式の visitor デリゲートを呼び出します。Reduces the node and then calls the visitor delegate on the reduced expression. ノードを単純化できない場合、このメソッドは例外をスローします。The method throws an exception if the node is not reducible.

(Inherited from Expression)

適用対象