GotoExpression Classe

Definição

Representa um salto incondicional. Isto inclui extratos de retorno, extratos de interrupção e continuação, e outros 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
Herança
GotoExpression

Exemplos

O exemplo seguinte demonstra como criar uma expressão que contenha um GotoExpression objeto usando o 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).

Propriedades

Name Description
CanReduce

Indica que o nó pode ser reduzido a um nó mais simples. Se isto devolver verdadeiro, Reduce() pode ser chamado para produzir a forma reduzida.

(Herdado de Expression)
Kind

O tipo de expressão de "referência". Serve apenas para fins informativos.

NodeType

Devolve o tipo de nó deste Expression.

Target

A etiqueta alvo para onde este nó salta.

Type

Obtém o tipo estático da expressão que isto Expression representa.

Value

O valor passado ao alvo, ou nulo se o alvo for do tipo System.Null.

Métodos

Name Description
Accept(ExpressionVisitor)

Despacha para o método de visita específico para este tipo de nó. Por exemplo, MethodCallExpression chama o VisitMethodCall(MethodCallExpression).

(Herdado de Expression)
Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetHashCode()

Serve como função de hash predefinida.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do atual Object.

(Herdado de Object)
Reduce()

Reduz este nó a uma expressão mais simples. Se o CanReduce devolver verdadeiro, isto deverá devolver uma expressão válida. Este método pode devolver outro nó que, por sua vez, deve ser reduzido.

(Herdado de Expression)
ReduceAndCheck()

Reduz este nó a uma expressão mais simples. Se o CanReduce devolver verdadeiro, isto deverá devolver uma expressão válida. Este método pode devolver outro nó que, por sua vez, deve ser reduzido.

(Herdado de Expression)
ReduceExtensions()

Reduz a expressão para um tipo de nó conhecido (que não é um nó de Extensão) ou simplesmente devolve a expressão se já for um tipo conhecido.

(Herdado de Expression)
ToString()

Devolve uma representação textual do Expression.

(Herdado de Expression)
Update(LabelTarget, Expression)

Cria uma nova expressão semelhante a esta, mas usando os filhos fornecidos. Se todas as crianças forem iguais, ela devolverá essa expressão.

VisitChildren(ExpressionVisitor)

Reduz o nó e depois chama o delegado visitante na expressão reduzida. O método lança uma exceção se o nó não for redutível.

(Herdado de Expression)

Aplica-se a