Expression<TDelegate>.Compile メソッド

定義

オーバーロード

Compile()

式ツリーによって記述されたラムダ式を実行可能コードにコンパイルし、ラムダ式を表すデリゲートを生成します。

Compile(Boolean)

式ツリーで記述されたラムダ式を、解釈されたまたはコンパイル済みコードにコンパイルし、そのラムダ式を表すデリゲートを生成します。

Compile(DebugInfoGenerator)

ラムダ式を表すデリゲートを作成します。

Compile()

式ツリーによって記述されたラムダ式を実行可能コードにコンパイルし、ラムダ式を表すデリゲートを生成します。

public:
 TDelegate Compile();
public TDelegate Compile ();
override this.Compile : unit -> 'Delegate
Public Function Compile () As TDelegate

戻り値

TDelegate

Expression<TDelegate> によって記述されたコンパイル済みのラムダ式を表す TDelegate 型のデリゲート。

次のコード例は、式ツリーの実行方法 Compile を示しています。


// Lambda expression as data in the form of an expression tree.
System.Linq.Expressions.Expression<Func<int, bool>> expr = i => i < 5;
// Compile the expression tree into executable code.
Func<int, bool> deleg = expr.Compile();
// Invoke the method and print the output.
Console.WriteLine("deleg(4) = {0}", deleg(4));

/*  This code produces the following output:

    deleg(4) = True
*/

' Lambda expression as data in the form of an expression tree.
Dim expression As System.Linq.Expressions.Expression(Of Func(Of Integer, Boolean)) = Function(ByVal i) i < 5
' Compile the expression tree into executable code.
Dim deleg As Func(Of Integer, Boolean) = expression.Compile()
' Invoke the method and print the output.
MsgBox(String.Format("deleg(4) = {0}", deleg(4)))

' This code produces the following output:
'
' deleg(4) = True

注釈

このメソッドは Compile 、実行時に型 TDelegate のデリゲートを生成します。 そのデリゲートが実行されると、そのデリゲートのセマンティクスによって記述された動作が含 Expression<TDelegate>まれます。

この Compile メソッドを使用して、任意の式ツリーの値を取得できます。 まず、メソッドを使用して、式を本体として持つラムダ式を Lambda 作成します。 次に、デリゲートを取得するために呼び出 Compile し、デリゲートを実行して式の値を取得します。

適用対象

Compile(Boolean)

式ツリーで記述されたラムダ式を、解釈されたまたはコンパイル済みコードにコンパイルし、そのラムダ式を表すデリゲートを生成します。

public:
 TDelegate Compile(bool preferInterpretation);
public TDelegate Compile (bool preferInterpretation);
override this.Compile : bool -> 'Delegate
Public Function Compile (preferInterpretation As Boolean) As TDelegate

パラメーター

preferInterpretation
Boolean

その式を解釈された形式にコンパイルすべきことを示す true (存在する場合)、それ以外の場合 false

戻り値

TDelegate

Expression<TDelegate> により記述されたコンパイル済みのラムダ式を表すデリゲート。

適用対象

Compile(DebugInfoGenerator)

ラムダ式を表すデリゲートを作成します。

public:
 TDelegate Compile(System::Runtime::CompilerServices::DebugInfoGenerator ^ debugInfoGenerator);
public TDelegate Compile (System.Runtime.CompilerServices.DebugInfoGenerator debugInfoGenerator);
override this.Compile : System.Runtime.CompilerServices.DebugInfoGenerator -> 'Delegate
Public Function Compile (debugInfoGenerator As DebugInfoGenerator) As TDelegate

パラメーター

debugInfoGenerator
DebugInfoGenerator

シーケンス ポイントをマークしたりローカル変数に注釈を付けたりするためにコンパイラが使用するデバッグ情報ジェネレーター。

戻り値

TDelegate

コンパイルされたバージョンのラムダを含んでいるデリゲート。

適用対象