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

Nombre Description
CanReduce

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

(Heredado de Expression)
Kind

El tipo de la expresión "ir a". Solo sirve para fines informativos.

NodeType

Devuelve el tipo de nodo de este Expression.

Target

Etiqueta de destino a la que 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

Nombre Description
Accept(ExpressionVisitor)

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

(Heredado de Expression)
Equals(Object)

Determina si el objeto especificado es igual al objeto actual.

(Heredado de Object)
GetHashCode()

Actúa 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 Objectactual.

(Heredado de Object)
Reduce()

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

(Heredado de Expression)
ReduceAndCheck()

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

(Heredado de Expression)
ReduceExtensions()

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

(Heredado de Expression)
ToString()

Devuelve una representación textual de .Expression

(Heredado de Expression)
Update(LabelTarget, Expression)

Crea una nueva expresión similar a esta, pero que usa los elementos secundarios proporcionados. Si todos los elementos secundarios son iguales, devolverá esta expresión.

VisitChildren(ExpressionVisitor)

Reduce el nodo y, a continuación, llama al delegado de visitante en la expresión reducida. El método produce una excepción si el nodo no se puede deducir.

(Heredado de Expression)

Se aplica a