Expression<TDelegate>.Compile メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
オーバーロード
| 名前 | 説明 |
|---|---|
| Compile() |
式ツリーによって記述されたラムダ式を実行可能コードにコンパイルし、ラムダ式を表すデリゲートを生成します。 |
| Compile(Boolean) |
式ツリーによって記述されたラムダ式を解釈されたコードまたはコンパイル済みコードにコンパイルし、ラムダ式を表すデリゲートを生成します。 |
| Compile(DebugInfoGenerator) |
ラムダ式を表すデリゲートを生成します。 |
Compile()
式ツリーによって記述されたラムダ式を実行可能コードにコンパイルし、ラムダ式を表すデリゲートを生成します。
public:
TDelegate Compile();
public TDelegate Compile();
override this.Compile : unit -> 'Delegate
Public Function Compile () As 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 。
返品
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
シーケンス ポイントをマークし、ローカル変数に注釈を付けるためにコンパイラによって使用されるデバッグ情報ジェネレーター。
返品
ラムダのコンパイル済みバージョンを含むデリゲート。