GotoExpression Класс
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Представляет безусловный переход. К ним относятся операторы возврата, прерывание и продолжение инструкций и другие переходы.
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
- Наследование
Примеры
В следующем примере показано, как создать выражение, содержащее GotoExpression объект с помощью Goto метода.
// 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).
Свойства
| Имя | Описание |
|---|---|
| CanReduce |
Указывает, что узел может быть сокращен до более простого узла. Если это возвращает значение true, можно вызвать reduce() для создания сокращенной формы. (Унаследовано от Expression) |
| Kind |
Тип выражения "перейти". Служит только сведениями. |
| NodeType |
Возвращает тип узла этого Expressionтипа. |
| Target |
Целевая метка, к которой переходит этот узел. |
| Type |
Возвращает статический тип выражения, представляющего это Expression выражение. |
| Value |
Значение, переданное целевому объекту или значение NULL, если целевой объект имеет тип System.Void. |
Методы
| Имя | Описание |
|---|---|
| Accept(ExpressionVisitor) |
Отправляется в конкретный метод посещения для этого типа узла. Например, MethodCallExpression вызывает объект VisitMethodCall(MethodCallExpression). (Унаследовано от Expression) |
| Equals(Object) |
Определяет, равен ли указанный объект текущему объекту. (Унаследовано от Object) |
| GetHashCode() |
Служит хэш-функцией по умолчанию. (Унаследовано от Object) |
| GetType() |
Возвращает Type текущего экземпляра. (Унаследовано от Object) |
| MemberwiseClone() |
Создает неглубокую копию текущей Object. (Унаследовано от Object) |
| Reduce() |
Сокращает этот узел до более простого выражения. Если CanReduce возвращает значение true, это должно возвращать допустимое выражение. Этот метод может возвращать другой узел, который должен быть сокращен. (Унаследовано от Expression) |
| ReduceAndCheck() |
Сокращает этот узел до более простого выражения. Если CanReduce возвращает значение true, это должно возвращать допустимое выражение. Этот метод может возвращать другой узел, который должен быть сокращен. (Унаследовано от Expression) |
| ReduceExtensions() |
Уменьшает выражение до известного типа узла (который не является узлом расширения) или просто возвращает выражение, если оно уже известного типа. (Унаследовано от Expression) |
| ToString() |
Возвращает текстовое представление Expressionобъекта . (Унаследовано от Expression) |
| Update(LabelTarget, Expression) |
Создает новое выражение, аналогичное этому, но используя предоставленные дочерние элементы. Если все дочерние элементы одинаковы, он вернет это выражение. |
| VisitChildren(ExpressionVisitor) |
Уменьшает узел, а затем вызывает делегат посетителя в сокращенном выражении. Метод создает исключение, если узел не является редуцируемым. (Унаследовано от Expression) |