Jazyk

GotoExpression Třída

Definice

Představuje bezpodmínečný skok. To zahrnuje návratové příkazy, přerušení a pokračování příkazů a další přeskakování.

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
Dědičnost
GotoExpression

Příklady

Následující příklad ukazuje, jak vytvořit výraz, který obsahuje GotoExpression objekt pomocí 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).

Vlastnosti

Name Description
CanReduce

Označuje, že uzel lze snížit na jednodušší uzel. Pokud se vrátí hodnota true, lze volat Reduce() k vytvoření snížené formy.

(Zděděno od Expression)
Kind

Druh výrazu "go to" (Přejít na) Slouží pouze pro účely informací.

NodeType

Vrátí typ uzlu tohoto Expression.

Target

Cílový popisek, na který tento uzel přeskočí.

Type

Získá statický typ výrazu, který představuje Expression .

Value

Hodnota předaná cíli nebo null, pokud je cíl typu System.Void.

Metody

Name Description
Accept(ExpressionVisitor)

Odešle konkrétní metodu návštěvy pro tento typ uzlu. MethodCallExpression Například volá .VisitMethodCall(MethodCallExpression)

(Zděděno od Expression)
Equals(Object)

Určuje, zda je zadaný objekt roven aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí funkce hash.

(Zděděno od Object)
GetType()

Získá Type aktuální instance.

(Zděděno od Object)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Object.

(Zděděno od Object)
Reduce()

Zmenší tento uzel na jednodušší výraz. Pokud CanReduce vrátí hodnotu true, měl by vrátit platný výraz. Tato metoda může vrátit jiný uzel, který se musí snížit.

(Zděděno od Expression)
ReduceAndCheck()

Zmenší tento uzel na jednodušší výraz. Pokud CanReduce vrátí hodnotu true, měl by vrátit platný výraz. Tato metoda může vrátit jiný uzel, který se musí snížit.

(Zděděno od Expression)
ReduceExtensions()

Zmenšuje výraz na známý typ uzlu (který není uzel rozšíření), nebo pouze vrátí výraz, pokud je již známým typem.

(Zděděno od Expression)
ToString()

Vrátí textovou reprezentaci Expression.

(Zděděno od Expression)
Update(LabelTarget, Expression)

Vytvoří nový výraz, který je podobný tomuto, ale použije zadané podřízené položky. Pokud jsou všechny podřízené položky stejné, vrátí tento výraz.

VisitChildren(ExpressionVisitor)

Zmenší uzel a potom zavolá delegáta návštěvníka na zkrácený výraz. Metoda vyvolá výjimku, pokud uzel není reducible.

(Zděděno od Expression)

Platí pro