GotoExpression Classe
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Representa um salto incondicional. Isso inclui o instruções de retorno, interrupção e continuação, entre 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
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).
Can |
Indica que o nó pode ser reduzido a um nó mais simples. Se isso retornar verdadeiro, Reduce() poderá ser chamado para produzir a forma reduzida. (Herdado de Expression) |
Kind |
O tipo da expressão "go to". Serve apenas para fins informativos. |
Node |
Retorna o tipo de nó deste Expression. |
Target |
O rótulo de destino para o qual este nó salta. |
Type |
Obtém o tipo estático da expressão que esse Expression representa. |
Value |
O valor passado para o destino ou nulo, se o destino é do tipo System.Void. |
Accept(Expression |
Expede o método específico de visita 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) |
Get |
Serve como a função de hash padrão. (Herdado de Object) |
Get |
Obtém o Type da instância atual. (Herdado de Object) |
Memberwise |
Cria uma cópia superficial do Object atual. (Herdado de Object) |
Reduce() |
Reduz esse nó a uma expressão mais simples. Se CanReduce retornar true, ele deverá retornar uma expressão válida. Esse método pode retornar outro nó que também precisa ser reduzido. (Herdado de Expression) |
Reduce |
Reduz esse nó a uma expressão mais simples. Se CanReduce retornar true, ele deverá retornar uma expressão válida. Esse método pode retornar outro nó que também precisa ser reduzido. (Herdado de Expression) |
Reduce |
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 ele já é um tipo conhecido. (Herdado de Expression) |
To |
Retorna uma representação textual de Expression. (Herdado de Expression) |
Update(Label |
Cria uma nova expressão que é parecida com esta, mas usando os filhos fornecidos. Se todos os filhos forem os mesmos, ela retornará esta expressão. |
Visit |
Reduz o nó e, em seguida, chama o delegado visitante na expressão reduzida. O método gera uma exceção se o nó não é reduzível. (Herdado de Expression) |
Produto | Versões |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
Comentários do .NET
O .NET é um projeto código aberto. Selecione um link para fornecer comentários: