GotoExpression Clase

Definición

Representa un salto incondicional. Esto incluye instrucciones return, instrucciones break y continue, y otros saltos.

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
Herencia
GotoExpression

Ejemplos

En el ejemplo siguiente se muestra cómo crear una expresión que contenga un GotoExpression objeto mediante el Goto método .

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

Propiedades

CanReduce

Indica que el nodo se puede reducir a uno más simple. Si devuelve true, se puede llamar a Reduce() para generar el formulario reducido.

(Heredado de Expression)
Kind

Tipo de la expresión "ir a". Solo tiene fines informativos.

NodeType

Devuelve el tipo de nodo de Expression.

Target

Etiqueta de destino a donde salta este nodo.

Type

Obtiene el tipo estático de la expresión que Expression representa.

Value

Valor pasado al destino o null si el destino es de tipo System.Void.

Métodos

Accept(ExpressionVisitor)

Envía la expresión al método de visita específico de este tipo de nodo. Por ejemplo, MethodCallExpression llama a VisitMethodCall(MethodCallExpression).

(Heredado de Expression)
Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.

(Heredado de Object)
GetHashCode()

Sirve como la función hash predeterminada.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
Reduce()

Reduce este nodo a una expresión más simple. Si CanReduce devuelve true, debería devolver una expresión válida. Este método puede devolver otro nodo que se debe reducir a su vez.

(Heredado de Expression)
ReduceAndCheck()

Reduce este nodo a una expresión más simple. Si CanReduce devuelve true, debería devolver una expresión válida. Este método puede devolver otro nodo que se debe reducir a su vez.

(Heredado de Expression)
ReduceExtensions()

Reduce la expresión a un tipo de nodo conocido (no es un nodo de extensión) o, si ya es un tipo conocido, solo devuelve la expresión.

(Heredado de Expression)
ToString()

Devuelve una representación textual de Expression.

(Heredado de Expression)
Update(LabelTarget, Expression)

Crea una nueva expresión que es como esta, pero usa el elemento secundario proporcionado. Si todos los elementos secundarios son iguales, devolverá esta expresión.

VisitChildren(ExpressionVisitor)

Reduce el nodo y, a continuación, llama al delegado del visitante en la expresión reducida. El método inicia una excepción si el nodo no es reducible.

(Heredado de Expression)

Se aplica a