GotoExpression Classe

Definição

Representa um salto incondicional. Isso inclui instruções de retorno, instruções break e continue 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 a seguir demonstra como criar uma expressão que contém 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

Nome Description
CanReduce

Indica que o nó pode ser reduzido a um nó mais simples. Se isso retornar true, Reduce() poderá ser chamado para produzir o formulário reduzido.

(Herdado de Expression)
Kind

O tipo de expressão "ir para". Serve somente para fins de informações.

NodeType

Retorna o tipo de nó deste Expression.

Target

O rótulo de destino para o qual esse nó salta.

Type

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

Value

O valor passado para o destino ou nulo se o destino for do tipo System.Void.

Métodos

Nome Description
Accept(ExpressionVisitor)

Envia para o método de visita específico para esse 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 a função hash predefinida.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do Objectatual.

(Herdado de Object)
Reduce()

Reduz esse nó a uma expressão mais simples. Se CanReduce retornar true, isso deverá retornar uma expressão válida. Esse método pode retornar outro nó que deve ser reduzido.

(Herdado de Expression)
ReduceAndCheck()

Reduz esse nó a uma expressão mais simples. Se CanReduce retornar true, isso deverá retornar uma expressão válida. Esse método pode retornar outro nó que deve ser reduzido.

(Herdado de Expression)
ReduceExtensions()

Reduz a expressão a um tipo de nó conhecido (que não é um nó de extensão) ou apenas retorna a expressão se já for um tipo conhecido.

(Herdado de Expression)
ToString()

Retorna 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 retornará essa expressão.

VisitChildren(ExpressionVisitor)

Reduz o nó e, em seguida, chama o delegado visitante na expressão reduzida. O método gerará uma exceção se o nó não for reduível.

(Herdado de Expression)

Aplica-se a