GotoExpression Klass

Definition

Representerar ett ovillkorligt hopp. Detta inkluderar returinstruktioner, break- och fortsätt-instruktioner och andra hopp.

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

Exempel

I följande exempel visas hur du skapar ett uttryck som innehåller ett GotoExpression objekt med hjälp Goto av metoden .

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

Egenskaper

Name Description
CanReduce

Anger att noden kan reduceras till en enklare nod. Om detta returnerar true kan Reduce() anropas för att skapa det reducerade formuläret.

(Ärvd från Expression)
Kind

Typen av "gå till"-uttryck. Endast informationssyfte.

NodeType

Returnerar nodtypen för den här Expression.

Target

Måletiketten där den här noden hoppar till.

Type

Hämtar den statiska typen av uttryck som detta Expression representerar.

Value

Värdet som skickas till målet eller null om målet är av typen System.Void.

Metoder

Name Description
Accept(ExpressionVisitor)

Skickar till den specifika besöksmetoden för den här nodtypen. Anropar MethodCallExpressionVisitMethodCall(MethodCallExpression)till exempel .

(Ärvd från Expression)
Equals(Object)

Avgör om det angivna objektet är lika med det aktuella objektet.

(Ärvd från Object)
GetHashCode()

Fungerar som standard-hash-funktion.

(Ärvd från Object)
GetType()

Hämtar den aktuella instansen Type .

(Ärvd från Object)
MemberwiseClone()

Skapar en ytlig kopia av den aktuella Object.

(Ärvd från Object)
Reduce()

Reducerar den här noden till ett enklare uttryck. Om CanReduce returnerar true bör detta returnera ett giltigt uttryck. Den här metoden kan returnera en annan nod som måste minskas.

(Ärvd från Expression)
ReduceAndCheck()

Reducerar den här noden till ett enklare uttryck. Om CanReduce returnerar true bör detta returnera ett giltigt uttryck. Den här metoden kan returnera en annan nod som måste minskas.

(Ärvd från Expression)
ReduceExtensions()

Minskar uttrycket till en känd nodtyp (som inte är en tilläggsnod) eller returnerar bara uttrycket om det redan är en känd typ.

(Ärvd från Expression)
ToString()

Returnerar en textrepresentation av Expression.

(Ärvd från Expression)
Update(LabelTarget, Expression)

Skapar ett nytt uttryck som liknar det här, men som använder de angivna underordnade uttrycken. Om alla underordnade är likadana returneras det här uttrycket.

VisitChildren(ExpressionVisitor)

Minskar noden och anropar sedan besökarens ombud för det reducerade uttrycket. Metoden genererar ett undantag om noden inte är redukterbar.

(Ärvd från Expression)

Gäller för