GotoExpression Classe

Definizione

Rappresenta un salto incondizionato. Sono incluse istruzioni return, break e continue e altri jump.

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 che contiene 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à

Nome Descrizione
CanReduce

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

(Ereditato da Expression)
Kind

Tipo di espressione "vai a". Serve solo informazioni.

NodeType

Restituisce il tipo di nodo dell'oggetto Expression.

Target

Etichetta di destinazione in cui si passa a questo nodo.

Type

Ottiene il tipo statico dell'espressione rappresentata da .Expression

Value

Valore passato alla destinazione o Null se la destinazione è di tipo System.Void.

Metodi

Nome Descrizione
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 il Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
Reduce()

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

(Ereditato da Expression)
ReduceAndCheck()

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

(Ereditato da Expression)
ReduceExtensions()

Riduce l'espressione a un tipo di nodo noto (che non è un nodo di estensione) o restituisce semplicemente l'espressione se è già un tipo noto.

(Ereditato da Expression)
ToString()

Restituisce una rappresentazione testuale dell'oggetto Expression.

(Ereditato da Expression)
Update(LabelTarget, Expression)

Crea una nuova espressione simile a questa, ma utilizzando gli elementi figlio forniti. Se tutti gli elementi figlio sono uguali, restituirà questa espressione.

VisitChildren(ExpressionVisitor)

Riduce il nodo e quindi chiama il delegato visitor nell'espressione ridotta. Il metodo genera un'eccezione se il nodo non è reducibile.

(Ereditato da Expression)

Si applica a