GotoExpression Klasa

Definicja

Reprezentuje bezwarunkowy skok. Obejmuje to instrukcje powrotu, instrukcje break i continue oraz inne skoki.

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

Przykłady

W poniższym przykładzie pokazano, jak utworzyć wyrażenie zawierające GotoExpression obiekt przy użyciu Goto metody .

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

Właściwości

CanReduce

Wskazuje, że węzeł można zmniejszyć do prostszego węzła. Jeśli zwraca wartość true, funkcja Reduce() może zostać wywołana w celu utworzenia skróconej postaci.

(Odziedziczone po Expression)
Kind

Rodzaj wyrażenia "przejdź do". Służy tylko do celów informacyjnych.

NodeType

Zwraca typ węzła tego Expressionelementu .

Target

Etykieta docelowa, do której ten węzeł przechodzi.

Type

Pobiera statyczny typ wyrażenia, które reprezentuje Expression .

Value

Wartość przekazana do obiektu docelowego lub wartość null, jeśli obiekt docelowy jest typu System.Void.

Metody

Accept(ExpressionVisitor)

Wysyła do określonej metody visit dla tego typu węzła. Na przykład MethodCallExpression wywołuje metodę VisitMethodCall(MethodCallExpression).

(Odziedziczone po Expression)
Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
Reduce()

Zmniejsza ten węzeł do prostszego wyrażenia. Jeśli funkcja CanReduce zwróci wartość true, powinno to zwrócić prawidłowe wyrażenie. Ta metoda może zwrócić inny węzeł, który należy zmniejszyć.

(Odziedziczone po Expression)
ReduceAndCheck()

Zmniejsza ten węzeł do prostszego wyrażenia. Jeśli funkcja CanReduce zwróci wartość true, powinno to zwrócić prawidłowe wyrażenie. Ta metoda może zwrócić inny węzeł, który należy zmniejszyć.

(Odziedziczone po Expression)
ReduceExtensions()

Zmniejsza wyrażenie do znanego typu węzła (który nie jest węzłem rozszerzenia) lub po prostu zwraca wyrażenie, jeśli jest to już znany typ.

(Odziedziczone po Expression)
ToString()

Zwraca tekstową reprezentację obiektu Expression.

(Odziedziczone po Expression)
Update(LabelTarget, Expression)

Tworzy nowe wyrażenie, które jest podobne do tego, ale przy użyciu dostarczonych elementów podrzędnych. Jeśli wszystkie elementy podrzędne są takie same, zwróci to wyrażenie.

VisitChildren(ExpressionVisitor)

Zmniejsza węzeł, a następnie wywołuje delegata odwiedzających w wyrażeniu zredukowanym. Metoda zgłasza wyjątek, jeśli węzeł nie jest reducible.

(Odziedziczone po Expression)

Dotyczy