BlockExpression クラス

定義

変数を定義できる式のシーケンスを格納するブロックを表します。

public ref class BlockExpression : System::Linq::Expressions::Expression
public class BlockExpression : System.Linq.Expressions.Expression
type BlockExpression = class
    inherit Expression
Public Class BlockExpression
Inherits Expression
継承
BlockExpression

次のコード例は、ブロック式を作成する方法を示しています。 ブロック式は、2 つの MethodCallExpression オブジェクトと 1 つの ConstantExpression オブジェクトで構成されます。

// Add the following directive to your file:
// using System.Linq.Expressions;

// The block expression allows for executing several expressions sequentually.
// When the block expression is executed,
// it returns the value of the last expression in the sequence.
BlockExpression blockExpr = Expression.Block(
    Expression.Call(
        null,
        typeof(Console).GetMethod("Write", new Type[] { typeof(String) }),
        Expression.Constant("Hello ")
       ),
    Expression.Call(
        null,
        typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
        Expression.Constant("World!")
        ),
    Expression.Constant(42)
);

Console.WriteLine("The result of executing the expression tree:");
// The following statement first creates an expression tree,
// then compiles it, and then executes it.
var result = Expression.Lambda<Func<int>>(blockExpr).Compile()();

// Print out the expressions from the block expression.
Console.WriteLine("The expressions from the block expression:");
foreach (var expr in blockExpr.Expressions)
    Console.WriteLine(expr.ToString());

// Print out the result of the tree execution.
Console.WriteLine("The return value of the block expression:");
Console.WriteLine(result);

// This code example produces the following output:
//
// The result of executing the expression tree:
// Hello World!

// The expressions from the block expression:
// Write("Hello ")
// WriteLine("World!")
// 42

// The return value of the block expression:
// 42
' Add the following directive to your file:
' Imports System.Linq.Expressions

' The block expression enables you to execute several expressions sequentually.
' When the block expression is executed,
' it returns the value of the last expression in the sequence.
Dim blockExpr As BlockExpression = Expression.Block(
    Expression.Call(
        Nothing,
        GetType(Console).GetMethod("Write", New Type() {GetType(String)}),
        Expression.Constant("Hello ")
       ),
    Expression.Call(
        Nothing,
        GetType(Console).GetMethod("WriteLine", New Type() {GetType(String)}),
        Expression.Constant("World!")
        ),
    Expression.Constant(42)
)

Console.WriteLine("The result of executing the expression tree:")
' The following statement first creates an expression tree,
' then compiles it, and then executes it.           
Dim result = Expression.Lambda(Of Func(Of Integer))(blockExpr).Compile()()

' Print the expressions from the block expression.
Console.WriteLine("The expressions from the block expression:")
For Each expr In blockExpr.Expressions
    Console.WriteLine(expr.ToString())
Next

' Print the result of the tree execution.
Console.WriteLine("The return value of the block expression:")
Console.WriteLine(result)

' This code example produces the following output:
'
' The result of executing the expression tree:
' Hello World!

' The expressions from the block expression:
' Write("Hello ")
' WriteLine("World!")
' 42

' The return value of the block expression:
' 42

注釈

メソッドを Block 使用して、 を BlockExpression作成できます。

プロパティ

CanReduce

ノードをより単純なノードに変形できることを示します。 これが true を返す場合、Reduce() を呼び出して単純化された形式を生成できます。

(継承元 Expression)
Expressions

このブロック内の式を取得します。

NodeType

この式のノード型を返します。 拡張ノードは、このメソッドをオーバーライドする際に Extension を返す必要があります。

Result

このブロック内の最後の式を取得します。

Type

この Expression が表す式の静的な型を取得します。

Variables

このブロックで定義されている変数を取得します。

メソッド

Accept(ExpressionVisitor)

このノード型の特定の Visit メソッドにデスパッチします。 たとえば、MethodCallExpressionVisitMethodCall(MethodCallExpression) を呼び出します。

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(IEnumerable<ParameterExpression>, IEnumerable<Expression>)

これに似た式ですが、指定された子を使用する、新しい式を作成します。 すべての子が同じである場合、この式を返します。

VisitChildren(ExpressionVisitor)

ノードを単純化し、単純化された式の visitor デリゲートを呼び出します。 ノードを単純化できない場合、このメソッドは例外をスローします。

(継承元 Expression)

適用対象