Share via


GotoExpression Kelas

Definisi

Mewakili lompatan tanpa syarat. Ini termasuk pernyataan pengembalian, pernyataan putus dan lanjutkan, dan lompatan lainnya.

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

Contoh

Contoh berikut menunjukkan cara membuat ekspresi yang berisi GotoExpression objek dengan menggunakan Goto metode .

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

Properti

CanReduce

Menunjukkan bahwa simpul dapat dikurangi menjadi simpul yang lebih sederhana. Jika ini mengembalikan true, Reduce() dapat dipanggil untuk menghasilkan formulir yang dikurangi.

(Diperoleh dari Expression)
Kind

Jenis ekspresi "buka". Hanya melayani tujuan informasi.

NodeType

Mengembalikan jenis node dari ini Expression.

Target

Label target tempat simpul ini melompat.

Type

Mendapatkan jenis statis ekspresi yang diwakili ini Expression .

Value

Nilai yang diteruskan ke target, atau null jika target berjenis System.Void.

Metode

Accept(ExpressionVisitor)

Dikirim ke metode kunjungan tertentu untuk jenis node ini. Misalnya, MethodCallExpression memanggil VisitMethodCall(MethodCallExpression).

(Diperoleh dari Expression)
Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetType()

Mendapatkan dari instans Type saat ini.

(Diperoleh dari Object)
MemberwiseClone()

Membuat salinan dangkal dari saat ini Object.

(Diperoleh dari Object)
Reduce()

Mengurangi simpul ini menjadi ekspresi yang lebih sederhana. Jika CanReduce mengembalikan true, ini akan mengembalikan ekspresi yang valid. Metode ini dapat mengembalikan simpul lain yang harus dikurangi.

(Diperoleh dari Expression)
ReduceAndCheck()

Mengurangi simpul ini menjadi ekspresi yang lebih sederhana. Jika CanReduce mengembalikan true, ini akan mengembalikan ekspresi yang valid. Metode ini dapat mengembalikan simpul lain yang harus dikurangi.

(Diperoleh dari Expression)
ReduceExtensions()

Mengurangi ekspresi ke jenis node yang diketahui (yang bukan node Ekstensi) atau hanya mengembalikan ekspresi jika sudah menjadi jenis yang diketahui.

(Diperoleh dari Expression)
ToString()

Mengembalikan representasi tekstual dari Expression.

(Diperoleh dari Expression)
Update(LabelTarget, Expression)

Membuat ekspresi baru yang seperti ini, tetapi menggunakan anak-anak yang disediakan. Jika semua anak sama, itu akan mengembalikan ekspresi ini.

VisitChildren(ExpressionVisitor)

Mengurangi simpul lalu memanggil delegasi pengunjung pada ekspresi yang dikurangi. Metode ini memberikan pengecualian jika node tidak dapat dikurangi.

(Diperoleh dari Expression)

Berlaku untuk