GotoExpression Classe

Definizione

Rappresenta un salto non condizionale. Include istruzioni return, istruzioni break e continue e altri salti.

public ref class GotoExpression sealed : System::Linq::Expressions::Expression
public sealed class GotoExpression : System.Linq.Expressions.Expression
type GotoExpression = class
    inherit Expression
Public NotInheritable Class GotoExpression
Inherits Expression
Ereditarietà
GotoExpression

Esempio

Nell'esempio seguente viene illustrato come creare un'espressione contenente un GotoExpression oggetto utilizzando il Goto metodo .

// Add the following directive to your file:
// using System.Linq.Expressions;

// A label expression of the void type that is the target for the GotoExpression.
LabelTarget returnTarget = Expression.Label();

// This block contains a GotoExpression.
// It transfers execution to a label expression that is initialized with the same LabelTarget as the GotoExpression.
// The types of the GotoExpression, label expression, and LabelTarget must match.
BlockExpression blockExpr =
    Expression.Block(
        Expression.Call(typeof(Console).GetMethod("WriteLine", new Type[] { typeof(string) }), Expression.Constant("GoTo")),
        Expression.Goto(returnTarget),
        Expression.Call(typeof(Console).GetMethod("WriteLine", new Type[] { typeof(string) }), Expression.Constant("Other Work")),
        Expression.Label(returnTarget)
    );

// The following statement first creates an expression tree,
// then compiles it, and then runs it.
Expression.Lambda<Action>(blockExpr).Compile()();

// This code example produces the following output:
//
// GoTo

// "Other Work" is not printed because
// the GoTo expression transfers execution from Expression.GoTo(returnTarget)
// to Expression.Label(returnTarget).
' Add the following directive to your file:
' Imports System.Linq.Expressions  

' A label expression of the void type that is the target for the GoToExpression.
Dim returnTarget As LabelTarget = Expression.Label()

' This block contains a GotoExpression.
' It transfers execution to a label expression that is initialized with the same LabelTarget as the GotoExpression.
' The types of the GotoExpression, label expression, and LabelTarget must match.
Dim blockExpr As BlockExpression =
      Expression.Block(
          Expression.Call(GetType(Console).GetMethod("WriteLine", New Type() {GetType(String)}), Expression.Constant("GoTo")),
          Expression.Goto(returnTarget),
          Expression.Call(GetType(Console).GetMethod("WriteLine", New Type() {GetType(String)}), Expression.Constant("Other Work")),
          Expression.Label(returnTarget)
      )

' The following statement first creates an expression tree,
' then compiles it, and then runs it.
Expression.Lambda(Of Action)(blockExpr).Compile()()

' This code example produces the following output:
'
' GoTo

' "Other Work" is not printed because 
' the Return expression transfers execution from Expression.GoTo(returnTarget)
' to Expression.Label(returnTarget).

Proprietà

CanReduce

Indica che il nodo può essere ridotto a un nodo più semplice. Se restituisce true, è possibile chiamare Reduce() per generare la forma ridotta.

(Ereditato da Expression)
Kind

Il tipo di espressione "go to". Ha solo scopi di informazione.

NodeType

Restituisce il tipo di nodo di Expression.

Target

L'etichetta della destinazione a cui salta questo nodo.

Type

Ottiene il tipo statico dell'espressione rappresentata da Expression.

Value

Il valore passato alla destinazione, oppure Null se la destinazione è di tipo System.Void.

Metodi

Accept(ExpressionVisitor)

Invia al metodo Visit specifico per questo tipo di nodo. Ad esempio, MethodCallExpression chiama VisitMethodCall(MethodCallExpression).

(Ereditato da Expression)
Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
Reduce()

Riduce questo nodo a un'espressione più semplice. Se CanReduce restituisce true, deve essere restituita un'espressione valida. Questo metodo può restituire un altro nodo che deve essere a sua volta ridotto.

(Ereditato da Expression)
ReduceAndCheck()

Riduce questo nodo a un'espressione più semplice. Se CanReduce restituisce true, deve essere restituita un'espressione valida. Questo metodo può restituire un altro nodo che deve essere a sua volta ridotto.

(Ereditato da Expression)
ReduceExtensions()

Riduce l'espressione a un tipo di nodo noto (diverso da un nodo di estensione) o restituisce solo l'espressione se è già un tipo noto.

(Ereditato da Expression)
ToString()

Restituisce una rappresentazione testuale di Expression.

(Ereditato da Expression)
Update(LabelTarget, Expression)

Crea una nuova espressione simile a questa, ma che usa gli elementi figlio specificati. Se tutti gli elementi figlio sono uguali, verrà restituita questa espressione.

VisitChildren(ExpressionVisitor)

Riduce il nodo, quindi chiama il delegato del visitatore sull'espressione ridotta. Se il nodo non è riducibile, il metodo genera un'eccezione.

(Ereditato da Expression)

Si applica a