ILGenerator.Emitとは? わかりやすく解説

ILGenerator.Emit メソッド (OpCode, ConstructorInfo)

命令MSIL (Microsoft Intermediate Language) ストリームに、指定したコンストラクタ指定した命令メタデータ トークン書き込みます

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<ComVisibleAttribute(True)> _
Public Overridable Sub Emit
 ( _
    opcode As OpCode, _
    con As ConstructorInfo _
)
Dim instance As ILGenerator
Dim opcode As OpCode
Dim con As ConstructorInfo

instance.Emit(opcode, con)
[ComVisibleAttribute(true)] 
public virtual void Emit (
    OpCode opcode,
    ConstructorInfo con
)
[ComVisibleAttribute(true)] 
public:
virtual void Emit (
    OpCode opcode, 
    ConstructorInfo^ con
)
/** @attribute ComVisibleAttribute(true) */ 
public void Emit (
    OpCode opcode, 
    ConstructorInfo con
)
ComVisibleAttribute(true) 
public function Emit (
    opcode : OpCode, 
    con : ConstructorInfo
)

パラメータ

opcode

ストリーム書き込む MSIL (Microsoft intermediate language) 命令

con

コンストラクタを表す ConstructorInfo

解説解説

この命令値は、OpCodes 列挙体で定義されている値にします。

モジュールポータブル実行可能 (PE) ファイル永続化するときに、必要に応じて命令ストリームパッチ当てることができるように、con位置記録されます。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.Emit メソッド (OpCode, FieldInfo)

命令MSIL (Microsoft Intermediate Language) ストリームに、指定したフィールド指定した命令メタデータ トークン書き込みます

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overridable Sub Emit
 ( _
    opcode As OpCode, _
    field As FieldInfo _
)
Dim instance As ILGenerator
Dim opcode As OpCode
Dim field As FieldInfo

instance.Emit(opcode, field)
public virtual void Emit (
    OpCode opcode,
    FieldInfo field
)
public:
virtual void Emit (
    OpCode opcode, 
    FieldInfo^ field
)
public void Emit (
    OpCode opcode, 
    FieldInfo field
)
public function Emit (
    opcode : OpCode, 
    field : FieldInfo
)

パラメータ

opcode

ストリーム書き込む MSIL (Microsoft intermediate language) 命令

field

フィールドを表す FieldInfo

解説解説

この命令値は、OpCodes 列挙体で定義されている値にします。モジュールPE永続化するときに、必要に応じて命令ストリームパッチ当てることができるように、field位置記録されます。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.Emit メソッド (OpCode, LocalBuilder)

指定され命令MSIL (Microsoft Intermediate Language) ストリーム書き込みその後ろに指定されローカル変数インデックス書き込みます

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overridable Sub Emit
 ( _
    opcode As OpCode, _
    local As LocalBuilder _
)
Dim instance As ILGenerator
Dim opcode As OpCode
Dim local As LocalBuilder

instance.Emit(opcode, local)
public virtual void Emit (
    OpCode opcode,
    LocalBuilder local
)
public:
virtual void Emit (
    OpCode opcode, 
    LocalBuilder^ local
)
public void Emit (
    OpCode opcode, 
    LocalBuilder local
)
public function Emit (
    opcode : OpCode, 
    local : LocalBuilder
)

パラメータ

opcode

ストリーム書き込む MSIL 命令

local

ローカル変数

例外例外
例外種類条件

ArgumentException

local の親メソッドが、この ILGenerator に関連付けられたメソッド一致しません。

ArgumentNullException

localnull 参照 (Visual Basic では Nothing) です。

InvalidOperationException

instruction1 バイト命令で、local は Byte.MaxValue を超えるインデックスローカル変数表します

解説解説

この命令値は、OpCodes 列挙体で定義されている値にします。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.Emit メソッド (OpCode, Int32)

命令MSIL (Microsoft Intermediate Language) ストリームに、指定した命令数値引数書き込みます

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overridable Sub Emit
 ( _
    opcode As OpCode, _
    arg As Integer _
)
Dim instance As ILGenerator
Dim opcode As OpCode
Dim arg As Integer

instance.Emit(opcode, arg)
public virtual void Emit (
    OpCode opcode,
    int arg
)
public:
virtual void Emit (
    OpCode opcode, 
    int arg
)
public void Emit (
    OpCode opcode, 
    int arg
)
public function Emit (
    opcode : OpCode, 
    arg : int
)

パラメータ

opcode

ストリーム書き込む MSIL (Microsoft intermediate language) 命令

arg

命令直後ストリーム書き込まれ数値引数

解説解説

この命令値は、OpCodes 列挙体で定義されている値にします。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.Emit メソッド (OpCode, SignatureHelper)

命令MSIL (Microsoft Intermediate Language) ストリームに、指定した命令シグネチャ トークン書き込みます

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overridable Sub Emit
 ( _
    opcode As OpCode, _
    signature As SignatureHelper _
)
Dim instance As ILGenerator
Dim opcode As OpCode
Dim signature As SignatureHelper

instance.Emit(opcode, signature)
public virtual void Emit (
    OpCode opcode,
    SignatureHelper signature
)
public:
virtual void Emit (
    OpCode opcode, 
    SignatureHelper^ signature
)
public void Emit (
    OpCode opcode, 
    SignatureHelper signature
)
public function Emit (
    opcode : OpCode, 
    signature : SignatureHelper
)

パラメータ

opcode

ストリーム書き込む MSIL (Microsoft intermediate language) 命令

signature

シグネチャ トークン構築するヘルパ

例外例外
例外種類条件

ArgumentNullException

signaturenull 参照 (Visual Basic では Nothing) です。

解説解説

この命令値は、OpCodes 列挙体で定義されている値にします。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.Emit メソッド

ジャスト イン タイム (JIT: Just In Time) コンパイラMSIL (Microsoft Intermediate Language) ストリーム命令書き込みます
オーバーロードの一覧オーバーロードの一覧

名前 説明
ILGenerator.Emit (OpCode) 指定され命令命令ストリーム書き込みます
ILGenerator.Emit (OpCode, Byte) 命令MSIL (Microsoft Intermediate Language) ストリームに、指定した命令文字引数書き込みます
ILGenerator.Emit (OpCode, ConstructorInfo) 命令MSIL (Microsoft Intermediate Language) ストリームに、指定したコンストラクタ指定した命令メタデータ トークン書き込みます
ILGenerator.Emit (OpCode, Double) 命令MSIL (Microsoft Intermediate Language) ストリームに、指定した命令数値引数書き込みます
ILGenerator.Emit (OpCode, FieldInfo) 命令MSIL (Microsoft Intermediate Language) ストリームに、指定したフィールド指定した命令メタデータ トークン書き込みます
ILGenerator.Emit (OpCode, Int16) 命令MSIL (Microsoft Intermediate Language) ストリームに、指定した命令数値引数書き込みます
ILGenerator.Emit (OpCode, Int32) 命令MSIL (Microsoft Intermediate Language) ストリームに、指定した命令数値引数書き込みます
ILGenerator.Emit (OpCode, Int64) 命令MSIL (Microsoft Intermediate Language) ストリームに、指定した命令数値引数書き込みます
ILGenerator.Emit (OpCode, Label) 指定され命令MSIL (Microsoft Intermediate Language) ストリーム書き込み位置確定した後でラベル格納する領域残します
ILGenerator.Emit (OpCode, Label[]) 指定され命令MSIL (Microsoft Intermediate Language) ストリーム書き込み位置確定した後でラベル格納する領域残します
ILGenerator.Emit (OpCode, LocalBuilder) 指定され命令MSIL (Microsoft Intermediate Language) ストリーム書き込みその後ろに指定されローカル変数インデックス書き込みます
ILGenerator.Emit (OpCode, MethodInfo) 指定され命令MSIL ストリーム書き込みその後ろに指定されメソッドメタデータ トークン書き込みます
ILGenerator.Emit (OpCode, SByte) 命令MSIL (Microsoft Intermediate Language) ストリームに、指定した命令文字引数書き込みます
ILGenerator.Emit (OpCode, SignatureHelper) 命令MSIL (Microsoft Intermediate Language) ストリームに、指定した命令シグネチャ トークン書き込みます
ILGenerator.Emit (OpCode, Single) 命令MSIL (Microsoft Intermediate Language) ストリームに、指定した命令数値引数書き込みます
ILGenerator.Emit (OpCode, String) 指定され命令MSIL ストリーム書き込みその後ろに指定され文字列メタデータ トークン書き込みます
ILGenerator.Emit (OpCode, Type) 指定され命令MSIL ストリーム書き込みその後ろに指定された型のメタデータ トークン書き込みます
参照参照

関連項目

ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.Emit メソッド (OpCode, Int64)

命令MSIL (Microsoft Intermediate Language) ストリームに、指定した命令数値引数書き込みます

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overridable Sub Emit
 ( _
    opcode As OpCode, _
    arg As Long _
)
Dim instance As ILGenerator
Dim opcode As OpCode
Dim arg As Long

instance.Emit(opcode, arg)
public virtual void Emit (
    OpCode opcode,
    long arg
)
public:
virtual void Emit (
    OpCode opcode, 
    long long arg
)
public void Emit (
    OpCode opcode, 
    long arg
)
public function Emit (
    opcode : OpCode, 
    arg : long
)

パラメータ

opcode

ストリーム書き込む MSIL (Microsoft intermediate language) 命令

arg

命令直後ストリーム書き込まれ数値引数

解説解説

この命令値は、OpCodes 列挙体で定義されている値にします。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.Emit メソッド (OpCode, MethodInfo)

指定され命令MSIL ストリーム書き込みその後ろに指定されメソッドメタデータ トークン書き込みます

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overridable Sub Emit
 ( _
    opcode As OpCode, _
    meth As MethodInfo _
)
Dim instance As ILGenerator
Dim opcode As OpCode
Dim meth As MethodInfo

instance.Emit(opcode, meth)
public virtual void Emit (
    OpCode opcode,
    MethodInfo meth
)
public:
virtual void Emit (
    OpCode opcode, 
    MethodInfo^ meth
)
public void Emit (
    OpCode opcode, 
    MethodInfo meth
)
public function Emit (
    opcode : OpCode, 
    meth : MethodInfo
)

パラメータ

opcode

ストリーム書き込む MSIL 命令

meth

メソッドを表す MethodInfo

例外例外
例外種類条件

ArgumentNullException

methnull 参照 (Visual Basic では Nothing) です。

NotSupportedException

meth は、MethodInfo.IsGenericMethodDefinition プロパティfalseジェネリック メソッドです。

解説解説

この命令値は、OpCodes 列挙体で定義されている値にします。

モジュール移植可能な実行可能ファイル永続化するときに、必要に応じて命令ストリームパッチ当てることができるように、meth位置記録されます。

methジェネリック メソッド表している場合は、ジェネリック メソッド定義にする必要があります。つまり、MethodInfo.IsGenericMethodDefinition プロパティtrueメソッドとする必要があります

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.Emit メソッド (OpCode, String)

指定され命令MSIL ストリーム書き込みその後ろに指定され文字列メタデータ トークン書き込みます

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overridable Sub Emit
 ( _
    opcode As OpCode, _
    str As String _
)
Dim instance As ILGenerator
Dim opcode As OpCode
Dim str As String

instance.Emit(opcode, str)
public virtual void Emit (
    OpCode opcode,
    string str
)
public:
virtual void Emit (
    OpCode opcode, 
    String^ str
)
public void Emit (
    OpCode opcode, 
    String str
)
public function Emit (
    opcode : OpCode, 
    str : String
)

パラメータ

opcode

ストリーム書き込む MSIL 命令

str

生成する文字列

解説解説

この命令値は、OpCodes 列挙体で定義されている値にします。モジュールPE永続化する場合将来のフィックスアップ用に str位置記録されます。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.Emit メソッド (OpCode, Byte)

命令MSIL (Microsoft Intermediate Language) ストリームに、指定した命令文字引数書き込みます

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overridable Sub Emit
 ( _
    opcode As OpCode, _
    arg As Byte _
)
Dim instance As ILGenerator
Dim opcode As OpCode
Dim arg As Byte

instance.Emit(opcode, arg)
public virtual void Emit (
    OpCode opcode,
    byte arg
)
public:
virtual void Emit (
    OpCode opcode, 
    unsigned char arg
)
public void Emit (
    OpCode opcode, 
    byte arg
)
public function Emit (
    opcode : OpCode, 
    arg : byte
)

パラメータ

opcode

ストリーム書き込む MSIL (Microsoft intermediate language) 命令

arg

命令直後ストリーム書き込む文字引数

解説解説

この命令値は、OpCodes 列挙体で定義されている値にします。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.Emit メソッド (OpCode, Int16)

命令MSIL (Microsoft Intermediate Language) ストリームに、指定した命令数値引数書き込みます

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overridable Sub Emit
 ( _
    opcode As OpCode, _
    arg As Short _
)
Dim instance As ILGenerator
Dim opcode As OpCode
Dim arg As Short

instance.Emit(opcode, arg)
public virtual void Emit (
    OpCode opcode,
    short arg
)
public:
virtual void Emit (
    OpCode opcode, 
    short arg
)
public void Emit (
    OpCode opcode, 
    short arg
)
public function Emit (
    opcode : OpCode, 
    arg : short
)

パラメータ

opcode

ストリーム書き込む MSIL (Microsoft intermediate language) 命令

arg

命令直後ストリーム格納する Int 引数

解説解説

この命令値は、OpCodes 列挙体で定義されている値にします。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.Emit メソッド (OpCode, Type)

指定され命令MSIL ストリーム書き込みその後ろに指定された型のメタデータ トークン書き込みます

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overridable Sub Emit
 ( _
    opcode As OpCode, _
    cls As Type _
)
Dim instance As ILGenerator
Dim opcode As OpCode
Dim cls As Type

instance.Emit(opcode, cls)
public virtual void Emit (
    OpCode opcode,
    Type cls
)
public:
virtual void Emit (
    OpCode opcode, 
    Type^ cls
)
public void Emit (
    OpCode opcode, 
    Type cls
)
public function Emit (
    opcode : OpCode, 
    cls : Type
)

パラメータ

opcode

ストリーム書き込む MSIL 命令

cls

Type

例外例外
例外種類条件

ArgumentNullException

clsnull 参照 (Visual Basic では Nothing) です。

解説解説

この命令値は、OpCodes 列挙体で定義されている値にします。モジュールPE永続化するときに、必要に応じてトークンパッチ当てることができるように、cls位置記録されます。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.Emit メソッド (OpCode, Label[])

指定され命令MSIL (Microsoft Intermediate Language) ストリーム書き込み位置確定した後でラベル格納する領域残します

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overridable Sub Emit
 ( _
    opcode As OpCode, _
    labels As Label() _
)
Dim instance As ILGenerator
Dim opcode As OpCode
Dim labels As Label()

instance.Emit(opcode, labels)
public virtual void Emit (
    OpCode opcode,
    Label[] labels
)
public:
virtual void Emit (
    OpCode opcode, 
    array<Label>^ labels
)
public void Emit (
    OpCode opcode, 
    Label[] labels
)
public function Emit (
    opcode : OpCode, 
    labels : Label[]
)

パラメータ

opcode

ストリーム書き込む MSIL (Microsoft intermediate language) 命令

labels

この位置から分岐するラベル オブジェクト配列すべてのラベル使用されます。

解説解説
使用例使用例

ジャンプ テーブルを持つ動的メソッド作成する方法次のコード例示しますジャンプ テーブルは、Label配列使用して作成します

Imports System
Imports System.Threading
Imports System.Reflection
Imports System.Reflection.Emit

 _

Class DynamicJumpTableDemo
   
   Public Shared Function
 BuildMyType() As Type

      Dim myDomain As AppDomain = Thread.GetDomain()
      Dim myAsmName As New
 AssemblyName()
      myAsmName.Name = "MyDynamicAssembly"
      
      Dim myAsmBuilder As AssemblyBuilder =
 myDomain.DefineDynamicAssembly(myAsmName, _
                            AssemblyBuilderAccess.Run)
      Dim myModBuilder As ModuleBuilder = myAsmBuilder.DefineDynamicModule("MyJumpTableDemo")
      
      Dim myTypeBuilder As TypeBuilder = myModBuilder.DefineType("JumpTableDemo",
 _
                                 TypeAttributes.Public)
      Dim myMthdBuilder As MethodBuilder =
 myTypeBuilder.DefineMethod("SwitchMe", _
                        MethodAttributes.Public Or MethodAttributes.Static,
 _
                        GetType(String), New
 Type() {GetType(Integer)})
      
      Dim myIL As ILGenerator = myMthdBuilder.GetILGenerator()
      
      Dim defaultCase As Label = myIL.DefineLabel()
      Dim endOfMethod As Label = myIL.DefineLabel()
      
      ' We are initializing our jump table. Note that the labels
      ' will be placed later using the MarkLabel method. 

      Dim jumpTable() As Label = {myIL.DefineLabel(),
 _
                  myIL.DefineLabel(), _
                  myIL.DefineLabel(), _
                  myIL.DefineLabel(), _
                  myIL.DefineLabel()}
      
      ' arg0, the number we passed, is pushed onto the stack.
      ' In this case, due to the design of the code sample,
      ' the value pushed onto the stack happens to match the
      ' index of the label (in IL terms, the index of the offset
      ' in the jump table). If this is not the case, such as
      ' when switching based on non-integer values, rules for the correspondence
      ' between the possible case values and each index of the offsets
      ' must be established outside of the ILGenerator.Emit calls,
      ' much as a compiler would.

      myIL.Emit(OpCodes.Ldarg_0)
      myIL.Emit(OpCodes.Switch, jumpTable)
      
      ' Branch on default case
      myIL.Emit(OpCodes.Br_S, defaultCase)
      
      ' Case arg0 = 0
      myIL.MarkLabel(jumpTable(0))
      myIL.Emit(OpCodes.Ldstr, "are no bananas")
      myIL.Emit(OpCodes.Br_S, endOfMethod)
      
      ' Case arg0 = 1
      myIL.MarkLabel(jumpTable(1))
      myIL.Emit(OpCodes.Ldstr, "is one banana")
      myIL.Emit(OpCodes.Br_S, endOfMethod)
      
      ' Case arg0 = 2
      myIL.MarkLabel(jumpTable(2))
      myIL.Emit(OpCodes.Ldstr, "are two bananas")
      myIL.Emit(OpCodes.Br_S, endOfMethod)
      
      ' Case arg0 = 3
      myIL.MarkLabel(jumpTable(3))
      myIL.Emit(OpCodes.Ldstr, "are three bananas")
      myIL.Emit(OpCodes.Br_S, endOfMethod)
      
      ' Case arg0 = 4
      myIL.MarkLabel(jumpTable(4))
      myIL.Emit(OpCodes.Ldstr, "are four bananas")
      myIL.Emit(OpCodes.Br_S, endOfMethod)
      
      ' Default case
      myIL.MarkLabel(defaultCase)
      myIL.Emit(OpCodes.Ldstr, "are many bananas")
      
      myIL.MarkLabel(endOfMethod)
      myIL.Emit(OpCodes.Ret)
      
      Return myTypeBuilder.CreateType()

   End Function 'BuildMyType
    
   
   Public Shared Sub Main()

      Dim myType As Type = BuildMyType()
      
      Console.Write("Enter an integer between 0 and 5: ")
      Dim theValue As Integer
 = Convert.ToInt32(Console.ReadLine())
      
      Console.WriteLine("---")
      Dim myInstance As [Object] = Activator.CreateInstance(myType,
 New Object() {})
      Console.WriteLine("Yes, there {0} today!", myType.InvokeMember("SwitchMe",
 _
                         BindingFlags.InvokeMethod, Nothing, _
                             myInstance, New Object()
 {theValue}))

   End Sub 'Main

End Class 'DynamicJumpTableDemo

using System;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;

class DynamicJumpTableDemo

{

   public static Type BuildMyType()
   {
    AppDomain myDomain = Thread.GetDomain();
    AssemblyName myAsmName = new AssemblyName();
    myAsmName.Name = "MyDynamicAssembly";

    AssemblyBuilder myAsmBuilder = myDomain.DefineDynamicAssembly(
                        myAsmName,
                        AssemblyBuilderAccess.Run);
    ModuleBuilder myModBuilder = myAsmBuilder.DefineDynamicModule(
                        "MyJumpTableDemo");

    TypeBuilder myTypeBuilder = myModBuilder.DefineType("JumpTableDemo"
,
                            TypeAttributes.Public);
    MethodBuilder myMthdBuilder = myTypeBuilder.DefineMethod("SwitchMe",
 
                             MethodAttributes.Public |
                             MethodAttributes.Static,
                                             typeof(string), 
                                             new Type[] {typeof(int)});

    ILGenerator myIL = myMthdBuilder.GetILGenerator();

    Label defaultCase = myIL.DefineLabel();    
    Label endOfMethod = myIL.DefineLabel();    

    // We are initializing our jump table. Note that the labels
    // will be placed later using the MarkLabel method. 

    Label[] jumpTable = new Label[] { myIL.DefineLabel(),
                      myIL.DefineLabel(),
                      myIL.DefineLabel(),
                      myIL.DefineLabel(),
                      myIL.DefineLabel() };

    // arg0, the number we passed, is pushed onto the stack.
    // In this case, due to the design of the code sample,
    // the value pushed onto the stack happens to match the
    // index of the label (in IL terms, the index of the offset
    // in the jump table). If this is not the case, such as
    // when switching based on non-integer values, rules for the correspondence
    // between the possible case values and each index of the offsets
    // must be established outside of the ILGenerator.Emit calls,
    // much as a compiler would.

    myIL.Emit(OpCodes.Ldarg_0);
    myIL.Emit(OpCodes.Switch, jumpTable);
    
    // Branch on default case
    myIL.Emit(OpCodes.Br_S, defaultCase);

    // Case arg0 = 0
    myIL.MarkLabel(jumpTable[0]); 
    myIL.Emit(OpCodes.Ldstr, "are no bananas");
    myIL.Emit(OpCodes.Br_S, endOfMethod);

    // Case arg0 = 1
    myIL.MarkLabel(jumpTable[1]); 
    myIL.Emit(OpCodes.Ldstr, "is one banana");
    myIL.Emit(OpCodes.Br_S, endOfMethod);

    // Case arg0 = 2
    myIL.MarkLabel(jumpTable[2]); 
    myIL.Emit(OpCodes.Ldstr, "are two bananas");
    myIL.Emit(OpCodes.Br_S, endOfMethod);

    // Case arg0 = 3
    myIL.MarkLabel(jumpTable[3]); 
    myIL.Emit(OpCodes.Ldstr, "are three bananas");
    myIL.Emit(OpCodes.Br_S, endOfMethod);

    // Case arg0 = 4
    myIL.MarkLabel(jumpTable[4]); 
    myIL.Emit(OpCodes.Ldstr, "are four bananas");
    myIL.Emit(OpCodes.Br_S, endOfMethod);

    // Default case
    myIL.MarkLabel(defaultCase);
    myIL.Emit(OpCodes.Ldstr, "are many bananas");

    myIL.MarkLabel(endOfMethod);
    myIL.Emit(OpCodes.Ret);
    
    return myTypeBuilder.CreateType();

   }

   public static void Main()
   {
    Type myType = BuildMyType();
    
    Console.Write("Enter an integer between 0 and 5: ");
    int theValue = Convert.ToInt32(Console.ReadLine());

    Console.WriteLine("---");
    Object myInstance = Activator.CreateInstance(myType, new object[0]);
    
    Console.WriteLine("Yes, there {0} today!", myType.InvokeMember("SwitchMe"
,
                                 BindingFlags.InvokeMethod,
                                 null,
                                 myInstance,
                                 new object[] {theValue}));  
              
   }

}

using namespace System;
using namespace System::Threading;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
Type^ BuildMyType()
{
   AppDomain^ myDomain = Thread::GetDomain();
   AssemblyName^ myAsmName = gcnew AssemblyName;
   myAsmName->Name = "MyDynamicAssembly";
   AssemblyBuilder^ myAsmBuilder = myDomain->DefineDynamicAssembly( myAsmName,
 AssemblyBuilderAccess::Run );
   ModuleBuilder^ myModBuilder = myAsmBuilder->DefineDynamicModule( "MyJumpTableDemo"
 );
   TypeBuilder^ myTypeBuilder = myModBuilder->DefineType( "JumpTableDemo",
 TypeAttributes::Public );
   array<Type^>^temp0 = {int::typeid};
   MethodBuilder^ myMthdBuilder = myTypeBuilder->DefineMethod( "SwitchMe",
 static_cast<MethodAttributes>(MethodAttributes::Public | MethodAttributes::Static),
 String::typeid, temp0 );
   ILGenerator^ myIL = myMthdBuilder->GetILGenerator();
   Label defaultCase = myIL->DefineLabel();
   Label endOfMethod = myIL->DefineLabel();
   
   // We are initializing our jump table. Note that the labels
   // will be placed later using the MarkLabel method.
   array<Label>^jumpTable = gcnew array<Label>(5);
   jumpTable[ 0 ] = myIL->DefineLabel();
   jumpTable[ 1 ] = myIL->DefineLabel();
   jumpTable[ 2 ] = myIL->DefineLabel();
   jumpTable[ 3 ] = myIL->DefineLabel();
   jumpTable[ 4 ] = myIL->DefineLabel();
   
   // arg0, the number we passed, is pushed onto the stack.
   // In this case, due to the design of the code sample,
   // the value pushed onto the stack happens to match the
   // index of the label (in IL terms, the index of the offset
   // in the jump table). If this is not the case, such as
   // when switching based on non-integer values, rules for the correspondence
   // between the possible case values and each index of the offsets
   // must be established outside of the ILGenerator::Emit calls,
   // much as a compiler would.
   myIL->Emit( OpCodes::Ldarg_0 );
   myIL->Emit( OpCodes::Switch, jumpTable );
   
   // Branch on default case
   myIL->Emit( OpCodes::Br_S, defaultCase );
   
   // Case arg0 = 0
   myIL->MarkLabel( jumpTable[ 0 ] );
   myIL->Emit( OpCodes::Ldstr, "are no bananas" );
   myIL->Emit( OpCodes::Br_S, endOfMethod );
   
   // Case arg0 = 1
   myIL->MarkLabel( jumpTable[ 1 ] );
   myIL->Emit( OpCodes::Ldstr, "is one banana" );
   myIL->Emit( OpCodes::Br_S, endOfMethod );
   
   // Case arg0 = 2
   myIL->MarkLabel( jumpTable[ 2 ] );
   myIL->Emit( OpCodes::Ldstr, "are two bananas" );
   myIL->Emit( OpCodes::Br_S, endOfMethod );
   
   // Case arg0 = 3
   myIL->MarkLabel( jumpTable[ 3 ] );
   myIL->Emit( OpCodes::Ldstr, "are three bananas" );
   myIL->Emit( OpCodes::Br_S, endOfMethod );
   
   // Case arg0 = 4
   myIL->MarkLabel( jumpTable[ 4 ] );
   myIL->Emit( OpCodes::Ldstr, "are four bananas" );
   myIL->Emit( OpCodes::Br_S, endOfMethod );
   
   // Default case
   myIL->MarkLabel( defaultCase );
   myIL->Emit( OpCodes::Ldstr, "are many bananas" );
   myIL->MarkLabel( endOfMethod );
   myIL->Emit( OpCodes::Ret );
   return myTypeBuilder->CreateType();
}

int main()
{
   Type^ myType = BuildMyType();
   Console::Write( "Enter an integer between 0 and 5: " );
   int theValue = Convert::ToInt32( Console::ReadLine() );
   Console::WriteLine( "---" );
   Object^ myInstance = Activator::CreateInstance( myType, gcnew array<Object^>(0)
 );
   array<Object^>^temp1 = {theValue};
   Console::WriteLine( "Yes, there {0} today!", myType->InvokeMember(
 "SwitchMe", BindingFlags::InvokeMethod, nullptr, myInstance, temp1 )
 );
}

import System .* ;
import System.Threading .* ;
import System.Reflection .* ;
import System.Reflection.Emit .* ;

class DynamicJumpTableDemo
{
    public static Type BuildMyType()
    {
        AppDomain myDomain = System.Threading.Thread.GetDomain();
        AssemblyName myAsmName = new AssemblyName();
        myAsmName.set_Name("MyDynamicAssembly");
        AssemblyBuilder myAsmBuilder = myDomain.DefineDynamicAssembly
            (myAsmName, AssemblyBuilderAccess.Run);
        ModuleBuilder myModBuilder = myAsmBuilder.DefineDynamicModule
            ("MyJumpTableDemo");
        TypeBuilder myTypeBuilder = myModBuilder.DefineType("JumpTableDemo"
,
            TypeAttributes.Public);
        MethodBuilder myMthdBuilder = myTypeBuilder.DefineMethod("SwitchMe"
,
            MethodAttributes.Public | MethodAttributes.Static,
            String.class.ToType(),new Type[]
 { int.class.ToType() });
        ILGenerator myIL = myMthdBuilder.GetILGenerator();
        Label defaultCase = myIL.DefineLabel();
        Label endOfMethod = myIL.DefineLabel();

        // We are initializing our jump table. Note that the labels
        // will be placed later using the MarkLabel method. 
        Label jumpTable[] = new Label[] { myIL.DefineLabel(),
            myIL.DefineLabel(), myIL.DefineLabel(), myIL.DefineLabel(),
            myIL.DefineLabel() };

        // arg0, the number we passed, is pushed onto the stack.
        // In this case, due to the design of the code sample,
        // the value pushed onto the stack happens to match the
        // index of the label (in IL terms, the index of the offset
        // in the jump table). If this is not the case, such as
        // when switching based on non-integer values, rules for the
 
        // correspondence between the possible case values and each
 index 
        // of the offsets must be established outside of the ILGenerator.
        // Emit calls, much as a compiler would.
        myIL.Emit(OpCodes.Ldarg_0);
        myIL.Emit(OpCodes.Switch, jumpTable);

        // Branch on default case
        myIL.Emit(OpCodes.Br_S, defaultCase);

        // Case arg0 = 0
        myIL.MarkLabel(jumpTable[0]);
        myIL.Emit(OpCodes.Ldstr, "are no bananas");
        myIL.Emit(OpCodes.Br_S, endOfMethod);

        // Case arg0 = 1
        myIL.MarkLabel(jumpTable[1]);
        myIL.Emit(OpCodes.Ldstr, "is one banana");
        myIL.Emit(OpCodes.Br_S, endOfMethod);

        // Case arg0 = 2
        myIL.MarkLabel(jumpTable[2]);
        myIL.Emit(OpCodes.Ldstr, "are two bananas");
        myIL.Emit(OpCodes.Br_S, endOfMethod);

        // Case arg0 = 3
        myIL.MarkLabel(jumpTable[3]);
        myIL.Emit(OpCodes.Ldstr, "are three bananas");
        myIL.Emit(OpCodes.Br_S, endOfMethod);

        // Case arg0 = 4
        myIL.MarkLabel(jumpTable[4]);
        myIL.Emit(OpCodes.Ldstr, "are four bananas");
        myIL.Emit(OpCodes.Br_S, endOfMethod);

        // Default case
        myIL.MarkLabel(defaultCase);
        myIL.Emit(OpCodes.Ldstr, "are many bananas");
        myIL.MarkLabel(endOfMethod);
        myIL.Emit(OpCodes.Ret);
        return myTypeBuilder.CreateType();
    } //BuildMyType    
   
   public static void main(String[]
 args)
   {
        Type myType = BuildMyType();
        Console.Write("Enter an integer between 0 and 5: ");
        int theValue = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("---");
        Object myInstance = Activator.CreateInstance(myType,new
 Object[0]);
        Console.WriteLine("Yes, there {0} today!",
            myType.InvokeMember("SwitchMe", BindingFlags.InvokeMethod,
            null, myInstance, new Object[]{(Int32)(theValue)}));
    } //main
} //DynamicJumpTableDemo
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.Emit メソッド (OpCode, Double)

命令MSIL (Microsoft Intermediate Language) ストリームに、指定した命令数値引数書き込みます

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overridable Sub Emit
 ( _
    opcode As OpCode, _
    arg As Double _
)
Dim instance As ILGenerator
Dim opcode As OpCode
Dim arg As Double

instance.Emit(opcode, arg)
public virtual void Emit (
    OpCode opcode,
    double arg
)
public:
virtual void Emit (
    OpCode opcode, 
    double arg
)
public void Emit (
    OpCode opcode, 
    double arg
)
public function Emit (
    opcode : OpCode, 
    arg : double
)

パラメータ

opcode

ストリーム書き込む MSIL (Microsoft intermediate language) 命令OpCodes 列挙体で定義されます。

arg

命令直後ストリーム書き込まれ数値引数

解説解説

この命令値は、OpCodes 列挙体で定義されている値にします。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.Emit メソッド (OpCode, SByte)

命令MSIL (Microsoft Intermediate Language) ストリームに、指定した命令文字引数書き込みます

このメソッドは、CLS準拠していません。  

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<CLSCompliantAttribute(False)> _
Public Sub Emit ( _
    opcode As OpCode, _
    arg As SByte _
)
Dim instance As ILGenerator
Dim opcode As OpCode
Dim arg As SByte

instance.Emit(opcode, arg)
[CLSCompliantAttribute(false)] 
public void Emit (
    OpCode opcode,
    sbyte arg
)
[CLSCompliantAttribute(false)] 
public:
void Emit (
    OpCode opcode, 
    signed char arg
)
/** @attribute CLSCompliantAttribute(false) */ 
public void Emit (
    OpCode opcode, 
    SByte arg
)
CLSCompliantAttribute(false) 
public function Emit (
    opcode : OpCode, 
    arg : sbyte
)

パラメータ

opcode

ストリーム書き込む MSIL (Microsoft intermediate language) 命令

arg

命令直後ストリーム書き込む文字引数

解説解説

この命令値は、OpCodes 列挙体で定義されている値にします。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.Emit メソッド (OpCode, Label)

指定され命令MSIL (Microsoft Intermediate Language) ストリーム書き込み位置確定した後でラベル格納する領域残します

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overridable Sub Emit
 ( _
    opcode As OpCode, _
    label As Label _
)
Dim instance As ILGenerator
Dim opcode As OpCode
Dim label As Label

instance.Emit(opcode, label)
public virtual void Emit (
    OpCode opcode,
    Label label
)
public:
virtual void Emit (
    OpCode opcode, 
    Label label
)
public void Emit (
    OpCode opcode, 
    Label label
)
public function Emit (
    opcode : OpCode, 
    label : Label
)

パラメータ

opcode

ストリーム書き込む MSIL (Microsoft intermediate language) 命令

label

この位置から分岐するラベル

解説解説

この命令値は、OpCodes 列挙体で定義されている値にします。

ラベルは、DefineLabel を使用して作成しますストリーム内のラベル位置は、MarkLabel を使用して確定します1 バイト命令使用する場合ラベルストリーム内で最大 127 バイトジャンプを表すことができますinstruction は、分岐命令を表す必要があります分岐相対的な命令であるため、label はフィックスアップ処理中に分岐への正しオフセット置き換えられます。

使用例使用例

ジャンプ テーブルを持つ動的メソッド作成する方法次のコード例示しますジャンプ テーブルは、Label配列使用して作成します

Imports System
Imports System.Threading
Imports System.Reflection
Imports System.Reflection.Emit

 _

Class DynamicJumpTableDemo
   
   Public Shared Function
 BuildMyType() As Type

      Dim myDomain As AppDomain = Thread.GetDomain()
      Dim myAsmName As New
 AssemblyName()
      myAsmName.Name = "MyDynamicAssembly"
      
      Dim myAsmBuilder As AssemblyBuilder =
 myDomain.DefineDynamicAssembly(myAsmName, _
                            AssemblyBuilderAccess.Run)
      Dim myModBuilder As ModuleBuilder = myAsmBuilder.DefineDynamicModule("MyJumpTableDemo")
      
      Dim myTypeBuilder As TypeBuilder = myModBuilder.DefineType("JumpTableDemo",
 _
                                 TypeAttributes.Public)
      Dim myMthdBuilder As MethodBuilder =
 myTypeBuilder.DefineMethod("SwitchMe", _
                        MethodAttributes.Public Or MethodAttributes.Static,
 _
                        GetType(String), New
 Type() {GetType(Integer)})
      
      Dim myIL As ILGenerator = myMthdBuilder.GetILGenerator()
      
      Dim defaultCase As Label = myIL.DefineLabel()
      Dim endOfMethod As Label = myIL.DefineLabel()
      
      ' We are initializing our jump table. Note that the labels
      ' will be placed later using the MarkLabel method. 

      Dim jumpTable() As Label = {myIL.DefineLabel(),
 _
                  myIL.DefineLabel(), _
                  myIL.DefineLabel(), _
                  myIL.DefineLabel(), _
                  myIL.DefineLabel()}
      
      ' arg0, the number we passed, is pushed onto the stack.
      ' In this case, due to the design of the code sample,
      ' the value pushed onto the stack happens to match the
      ' index of the label (in IL terms, the index of the offset
      ' in the jump table). If this is not the case, such as
      ' when switching based on non-integer values, rules for the correspondence
      ' between the possible case values and each index of the offsets
      ' must be established outside of the ILGenerator.Emit calls,
      ' much as a compiler would.

      myIL.Emit(OpCodes.Ldarg_0)
      myIL.Emit(OpCodes.Switch, jumpTable)
      
      ' Branch on default case
      myIL.Emit(OpCodes.Br_S, defaultCase)
      
      ' Case arg0 = 0
      myIL.MarkLabel(jumpTable(0))
      myIL.Emit(OpCodes.Ldstr, "are no bananas")
      myIL.Emit(OpCodes.Br_S, endOfMethod)
      
      ' Case arg0 = 1
      myIL.MarkLabel(jumpTable(1))
      myIL.Emit(OpCodes.Ldstr, "is one banana")
      myIL.Emit(OpCodes.Br_S, endOfMethod)
      
      ' Case arg0 = 2
      myIL.MarkLabel(jumpTable(2))
      myIL.Emit(OpCodes.Ldstr, "are two bananas")
      myIL.Emit(OpCodes.Br_S, endOfMethod)
      
      ' Case arg0 = 3
      myIL.MarkLabel(jumpTable(3))
      myIL.Emit(OpCodes.Ldstr, "are three bananas")
      myIL.Emit(OpCodes.Br_S, endOfMethod)
      
      ' Case arg0 = 4
      myIL.MarkLabel(jumpTable(4))
      myIL.Emit(OpCodes.Ldstr, "are four bananas")
      myIL.Emit(OpCodes.Br_S, endOfMethod)
      
      ' Default case
      myIL.MarkLabel(defaultCase)
      myIL.Emit(OpCodes.Ldstr, "are many bananas")
      
      myIL.MarkLabel(endOfMethod)
      myIL.Emit(OpCodes.Ret)
      
      Return myTypeBuilder.CreateType()

   End Function 'BuildMyType
    
   
   Public Shared Sub Main()

      Dim myType As Type = BuildMyType()
      
      Console.Write("Enter an integer between 0 and 5: ")
      Dim theValue As Integer
 = Convert.ToInt32(Console.ReadLine())
      
      Console.WriteLine("---")
      Dim myInstance As [Object] = Activator.CreateInstance(myType,
 New Object() {})
      Console.WriteLine("Yes, there {0} today!", myType.InvokeMember("SwitchMe",
 _
                         BindingFlags.InvokeMethod, Nothing, _
                             myInstance, New Object()
 {theValue}))

   End Sub 'Main

End Class 'DynamicJumpTableDemo

using System;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;

class DynamicJumpTableDemo

{

   public static Type BuildMyType()
   {
    AppDomain myDomain = Thread.GetDomain();
    AssemblyName myAsmName = new AssemblyName();
    myAsmName.Name = "MyDynamicAssembly";

    AssemblyBuilder myAsmBuilder = myDomain.DefineDynamicAssembly(
                        myAsmName,
                        AssemblyBuilderAccess.Run);
    ModuleBuilder myModBuilder = myAsmBuilder.DefineDynamicModule(
                        "MyJumpTableDemo");

    TypeBuilder myTypeBuilder = myModBuilder.DefineType("JumpTableDemo"
,
                            TypeAttributes.Public);
    MethodBuilder myMthdBuilder = myTypeBuilder.DefineMethod("SwitchMe",
 
                             MethodAttributes.Public |
                             MethodAttributes.Static,
                                             typeof(string), 
                                             new Type[] {typeof(int)});

    ILGenerator myIL = myMthdBuilder.GetILGenerator();

    Label defaultCase = myIL.DefineLabel();    
    Label endOfMethod = myIL.DefineLabel();    

    // We are initializing our jump table. Note that the labels
    // will be placed later using the MarkLabel method. 

    Label[] jumpTable = new Label[] { myIL.DefineLabel(),
                      myIL.DefineLabel(),
                      myIL.DefineLabel(),
                      myIL.DefineLabel(),
                      myIL.DefineLabel() };

    // arg0, the number we passed, is pushed onto the stack.
    // In this case, due to the design of the code sample,
    // the value pushed onto the stack happens to match the
    // index of the label (in IL terms, the index of the offset
    // in the jump table). If this is not the case, such as
    // when switching based on non-integer values, rules for the correspondence
    // between the possible case values and each index of the offsets
    // must be established outside of the ILGenerator.Emit calls,
    // much as a compiler would.

    myIL.Emit(OpCodes.Ldarg_0);
    myIL.Emit(OpCodes.Switch, jumpTable);
    
    // Branch on default case
    myIL.Emit(OpCodes.Br_S, defaultCase);

    // Case arg0 = 0
    myIL.MarkLabel(jumpTable[0]); 
    myIL.Emit(OpCodes.Ldstr, "are no bananas");
    myIL.Emit(OpCodes.Br_S, endOfMethod);

    // Case arg0 = 1
    myIL.MarkLabel(jumpTable[1]); 
    myIL.Emit(OpCodes.Ldstr, "is one banana");
    myIL.Emit(OpCodes.Br_S, endOfMethod);

    // Case arg0 = 2
    myIL.MarkLabel(jumpTable[2]); 
    myIL.Emit(OpCodes.Ldstr, "are two bananas");
    myIL.Emit(OpCodes.Br_S, endOfMethod);

    // Case arg0 = 3
    myIL.MarkLabel(jumpTable[3]); 
    myIL.Emit(OpCodes.Ldstr, "are three bananas");
    myIL.Emit(OpCodes.Br_S, endOfMethod);

    // Case arg0 = 4
    myIL.MarkLabel(jumpTable[4]); 
    myIL.Emit(OpCodes.Ldstr, "are four bananas");
    myIL.Emit(OpCodes.Br_S, endOfMethod);

    // Default case
    myIL.MarkLabel(defaultCase);
    myIL.Emit(OpCodes.Ldstr, "are many bananas");

    myIL.MarkLabel(endOfMethod);
    myIL.Emit(OpCodes.Ret);
    
    return myTypeBuilder.CreateType();

   }

   public static void Main()
   {
    Type myType = BuildMyType();
    
    Console.Write("Enter an integer between 0 and 5: ");
    int theValue = Convert.ToInt32(Console.ReadLine());

    Console.WriteLine("---");
    Object myInstance = Activator.CreateInstance(myType, new object[0]);
    
    Console.WriteLine("Yes, there {0} today!", myType.InvokeMember("SwitchMe"
,
                                 BindingFlags.InvokeMethod,
                                 null,
                                 myInstance,
                                 new object[] {theValue}));  
              
   }

}

using namespace System;
using namespace System::Threading;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
Type^ BuildMyType()
{
   AppDomain^ myDomain = Thread::GetDomain();
   AssemblyName^ myAsmName = gcnew AssemblyName;
   myAsmName->Name = "MyDynamicAssembly";
   AssemblyBuilder^ myAsmBuilder = myDomain->DefineDynamicAssembly( myAsmName,
 AssemblyBuilderAccess::Run );
   ModuleBuilder^ myModBuilder = myAsmBuilder->DefineDynamicModule( "MyJumpTableDemo"
 );
   TypeBuilder^ myTypeBuilder = myModBuilder->DefineType( "JumpTableDemo",
 TypeAttributes::Public );
   array<Type^>^temp0 = {int::typeid};
   MethodBuilder^ myMthdBuilder = myTypeBuilder->DefineMethod( "SwitchMe",
 static_cast<MethodAttributes>(MethodAttributes::Public | MethodAttributes::Static),
 String::typeid, temp0 );
   ILGenerator^ myIL = myMthdBuilder->GetILGenerator();
   Label defaultCase = myIL->DefineLabel();
   Label endOfMethod = myIL->DefineLabel();
   
   // We are initializing our jump table. Note that the labels
   // will be placed later using the MarkLabel method.
   array<Label>^jumpTable = gcnew array<Label>(5);
   jumpTable[ 0 ] = myIL->DefineLabel();
   jumpTable[ 1 ] = myIL->DefineLabel();
   jumpTable[ 2 ] = myIL->DefineLabel();
   jumpTable[ 3 ] = myIL->DefineLabel();
   jumpTable[ 4 ] = myIL->DefineLabel();
   
   // arg0, the number we passed, is pushed onto the stack.
   // In this case, due to the design of the code sample,
   // the value pushed onto the stack happens to match the
   // index of the label (in IL terms, the index of the offset
   // in the jump table). If this is not the case, such as
   // when switching based on non-integer values, rules for the correspondence
   // between the possible case values and each index of the offsets
   // must be established outside of the ILGenerator::Emit calls,
   // much as a compiler would.
   myIL->Emit( OpCodes::Ldarg_0 );
   myIL->Emit( OpCodes::Switch, jumpTable );
   
   // Branch on default case
   myIL->Emit( OpCodes::Br_S, defaultCase );
   
   // Case arg0 = 0
   myIL->MarkLabel( jumpTable[ 0 ] );
   myIL->Emit( OpCodes::Ldstr, "are no bananas" );
   myIL->Emit( OpCodes::Br_S, endOfMethod );
   
   // Case arg0 = 1
   myIL->MarkLabel( jumpTable[ 1 ] );
   myIL->Emit( OpCodes::Ldstr, "is one banana" );
   myIL->Emit( OpCodes::Br_S, endOfMethod );
   
   // Case arg0 = 2
   myIL->MarkLabel( jumpTable[ 2 ] );
   myIL->Emit( OpCodes::Ldstr, "are two bananas" );
   myIL->Emit( OpCodes::Br_S, endOfMethod );
   
   // Case arg0 = 3
   myIL->MarkLabel( jumpTable[ 3 ] );
   myIL->Emit( OpCodes::Ldstr, "are three bananas" );
   myIL->Emit( OpCodes::Br_S, endOfMethod );
   
   // Case arg0 = 4
   myIL->MarkLabel( jumpTable[ 4 ] );
   myIL->Emit( OpCodes::Ldstr, "are four bananas" );
   myIL->Emit( OpCodes::Br_S, endOfMethod );
   
   // Default case
   myIL->MarkLabel( defaultCase );
   myIL->Emit( OpCodes::Ldstr, "are many bananas" );
   myIL->MarkLabel( endOfMethod );
   myIL->Emit( OpCodes::Ret );
   return myTypeBuilder->CreateType();
}

int main()
{
   Type^ myType = BuildMyType();
   Console::Write( "Enter an integer between 0 and 5: " );
   int theValue = Convert::ToInt32( Console::ReadLine() );
   Console::WriteLine( "---" );
   Object^ myInstance = Activator::CreateInstance( myType, gcnew array<Object^>(0)
 );
   array<Object^>^temp1 = {theValue};
   Console::WriteLine( "Yes, there {0} today!", myType->InvokeMember(
 "SwitchMe", BindingFlags::InvokeMethod, nullptr, myInstance, temp1 )
 );
}

import System .* ;
import System.Threading .* ;
import System.Reflection .* ;
import System.Reflection.Emit .* ;

class DynamicJumpTableDemo
{
    public static Type BuildMyType()
    {
        AppDomain myDomain = System.Threading.Thread.GetDomain();
        AssemblyName myAsmName = new AssemblyName();
        myAsmName.set_Name("MyDynamicAssembly");
        AssemblyBuilder myAsmBuilder = myDomain.DefineDynamicAssembly
            (myAsmName, AssemblyBuilderAccess.Run);
        ModuleBuilder myModBuilder = myAsmBuilder.DefineDynamicModule
            ("MyJumpTableDemo");
        TypeBuilder myTypeBuilder = myModBuilder.DefineType("JumpTableDemo"
,
            TypeAttributes.Public);
        MethodBuilder myMthdBuilder = myTypeBuilder.DefineMethod("SwitchMe"
,
            MethodAttributes.Public | MethodAttributes.Static,
            String.class.ToType(),new Type[]
 { int.class.ToType() });
        ILGenerator myIL = myMthdBuilder.GetILGenerator();
        Label defaultCase = myIL.DefineLabel();
        Label endOfMethod = myIL.DefineLabel();

        // We are initializing our jump table. Note that the labels
        // will be placed later using the MarkLabel method. 
        Label jumpTable[] = new Label[] { myIL.DefineLabel(),
            myIL.DefineLabel(), myIL.DefineLabel(), myIL.DefineLabel(),
            myIL.DefineLabel() };

        // arg0, the number we passed, is pushed onto the stack.
        // In this case, due to the design of the code sample,
        // the value pushed onto the stack happens to match the
        // index of the label (in IL terms, the index of the offset
        // in the jump table). If this is not the case, such as
        // when switching based on non-integer values, rules for the
 
        // correspondence between the possible case values and each
 index 
        // of the offsets must be established outside of the ILGenerator.
        // Emit calls, much as a compiler would.
        myIL.Emit(OpCodes.Ldarg_0);
        myIL.Emit(OpCodes.Switch, jumpTable);

        // Branch on default case
        myIL.Emit(OpCodes.Br_S, defaultCase);

        // Case arg0 = 0
        myIL.MarkLabel(jumpTable[0]);
        myIL.Emit(OpCodes.Ldstr, "are no bananas");
        myIL.Emit(OpCodes.Br_S, endOfMethod);

        // Case arg0 = 1
        myIL.MarkLabel(jumpTable[1]);
        myIL.Emit(OpCodes.Ldstr, "is one banana");
        myIL.Emit(OpCodes.Br_S, endOfMethod);

        // Case arg0 = 2
        myIL.MarkLabel(jumpTable[2]);
        myIL.Emit(OpCodes.Ldstr, "are two bananas");
        myIL.Emit(OpCodes.Br_S, endOfMethod);

        // Case arg0 = 3
        myIL.MarkLabel(jumpTable[3]);
        myIL.Emit(OpCodes.Ldstr, "are three bananas");
        myIL.Emit(OpCodes.Br_S, endOfMethod);

        // Case arg0 = 4
        myIL.MarkLabel(jumpTable[4]);
        myIL.Emit(OpCodes.Ldstr, "are four bananas");
        myIL.Emit(OpCodes.Br_S, endOfMethod);

        // Default case
        myIL.MarkLabel(defaultCase);
        myIL.Emit(OpCodes.Ldstr, "are many bananas");
        myIL.MarkLabel(endOfMethod);
        myIL.Emit(OpCodes.Ret);
        return myTypeBuilder.CreateType();
    } //BuildMyType    
   
   public static void main(String[]
 args)
   {
        Type myType = BuildMyType();
        Console.Write("Enter an integer between 0 and 5: ");
        int theValue = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("---");
        Object myInstance = Activator.CreateInstance(myType,new
 Object[0]);
        Console.WriteLine("Yes, there {0} today!",
            myType.InvokeMember("SwitchMe", BindingFlags.InvokeMethod,
            null, myInstance, new Object[]{(Int32)(theValue)}));
    } //main
} //DynamicJumpTableDemo
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.Emit メソッド (OpCode)

指定され命令命令ストリーム書き込みます

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overridable Sub Emit
 ( _
    opcode As OpCode _
)
Dim instance As ILGenerator
Dim opcode As OpCode

instance.Emit(opcode)
public virtual void Emit (
    OpCode opcode
)
public:
virtual void Emit (
    OpCode opcode
)
public void Emit (
    OpCode opcode
)
public function Emit (
    opcode : OpCode
)

パラメータ

opcode

ストリーム書き込む MSIL (Microsoft Intermediate Language) 命令

解説解説
使用例使用例

Emit使用し、ILGenerator のインスタンス通じて MSIL 出力生成する方法次のコード例示します

Imports System
Imports System.Threading
Imports System.Reflection
Imports System.Reflection.Emit

 _

Class DynamicJumpTableDemo
   
   Public Shared Function
 BuildMyType() As Type

      Dim myDomain As AppDomain = Thread.GetDomain()
      Dim myAsmName As New
 AssemblyName()
      myAsmName.Name = "MyDynamicAssembly"
      
      Dim myAsmBuilder As AssemblyBuilder =
 myDomain.DefineDynamicAssembly(myAsmName, _
                            AssemblyBuilderAccess.Run)
      Dim myModBuilder As ModuleBuilder = myAsmBuilder.DefineDynamicModule("MyJumpTableDemo")
      
      Dim myTypeBuilder As TypeBuilder = myModBuilder.DefineType("JumpTableDemo",
 _
                                 TypeAttributes.Public)
      Dim myMthdBuilder As MethodBuilder =
 myTypeBuilder.DefineMethod("SwitchMe", _
                        MethodAttributes.Public Or MethodAttributes.Static,
 _
                        GetType(String), New
 Type() {GetType(Integer)})
      
      Dim myIL As ILGenerator = myMthdBuilder.GetILGenerator()
      
      Dim defaultCase As Label = myIL.DefineLabel()
      Dim endOfMethod As Label = myIL.DefineLabel()
      
      ' We are initializing our jump table. Note that the labels
      ' will be placed later using the MarkLabel method. 

      Dim jumpTable() As Label = {myIL.DefineLabel(),
 _
                  myIL.DefineLabel(), _
                  myIL.DefineLabel(), _
                  myIL.DefineLabel(), _
                  myIL.DefineLabel()}
      
      ' arg0, the number we passed, is pushed onto the stack.
      ' In this case, due to the design of the code sample,
      ' the value pushed onto the stack happens to match the
      ' index of the label (in IL terms, the index of the offset
      ' in the jump table). If this is not the case, such as
      ' when switching based on non-integer values, rules for the correspondence
      ' between the possible case values and each index of the offsets
      ' must be established outside of the ILGenerator.Emit calls,
      ' much as a compiler would.

      myIL.Emit(OpCodes.Ldarg_0)
      myIL.Emit(OpCodes.Switch, jumpTable)
      
      ' Branch on default case
      myIL.Emit(OpCodes.Br_S, defaultCase)
      
      ' Case arg0 = 0
      myIL.MarkLabel(jumpTable(0))
      myIL.Emit(OpCodes.Ldstr, "are no bananas")
      myIL.Emit(OpCodes.Br_S, endOfMethod)
      
      ' Case arg0 = 1
      myIL.MarkLabel(jumpTable(1))
      myIL.Emit(OpCodes.Ldstr, "is one banana")
      myIL.Emit(OpCodes.Br_S, endOfMethod)
      
      ' Case arg0 = 2
      myIL.MarkLabel(jumpTable(2))
      myIL.Emit(OpCodes.Ldstr, "are two bananas")
      myIL.Emit(OpCodes.Br_S, endOfMethod)
      
      ' Case arg0 = 3
      myIL.MarkLabel(jumpTable(3))
      myIL.Emit(OpCodes.Ldstr, "are three bananas")
      myIL.Emit(OpCodes.Br_S, endOfMethod)
      
      ' Case arg0 = 4
      myIL.MarkLabel(jumpTable(4))
      myIL.Emit(OpCodes.Ldstr, "are four bananas")
      myIL.Emit(OpCodes.Br_S, endOfMethod)
      
      ' Default case
      myIL.MarkLabel(defaultCase)
      myIL.Emit(OpCodes.Ldstr, "are many bananas")
      
      myIL.MarkLabel(endOfMethod)
      myIL.Emit(OpCodes.Ret)
      
      Return myTypeBuilder.CreateType()

   End Function 'BuildMyType
    
   
   Public Shared Sub Main()

      Dim myType As Type = BuildMyType()
      
      Console.Write("Enter an integer between 0 and 5: ")
      Dim theValue As Integer
 = Convert.ToInt32(Console.ReadLine())
      
      Console.WriteLine("---")
      Dim myInstance As [Object] = Activator.CreateInstance(myType,
 New Object() {})
      Console.WriteLine("Yes, there {0} today!", myType.InvokeMember("SwitchMe",
 _
                         BindingFlags.InvokeMethod, Nothing, _
                             myInstance, New Object()
 {theValue}))

   End Sub 'Main

End Class 'DynamicJumpTableDemo

using System;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;

class DynamicJumpTableDemo

{

   public static Type BuildMyType()
   {
    AppDomain myDomain = Thread.GetDomain();
    AssemblyName myAsmName = new AssemblyName();
    myAsmName.Name = "MyDynamicAssembly";

    AssemblyBuilder myAsmBuilder = myDomain.DefineDynamicAssembly(
                        myAsmName,
                        AssemblyBuilderAccess.Run);
    ModuleBuilder myModBuilder = myAsmBuilder.DefineDynamicModule(
                        "MyJumpTableDemo");

    TypeBuilder myTypeBuilder = myModBuilder.DefineType("JumpTableDemo"
,
                            TypeAttributes.Public);
    MethodBuilder myMthdBuilder = myTypeBuilder.DefineMethod("SwitchMe",
 
                             MethodAttributes.Public |
                             MethodAttributes.Static,
                                             typeof(string), 
                                             new Type[] {typeof(int)});

    ILGenerator myIL = myMthdBuilder.GetILGenerator();

    Label defaultCase = myIL.DefineLabel();    
    Label endOfMethod = myIL.DefineLabel();    

    // We are initializing our jump table. Note that the labels
    // will be placed later using the MarkLabel method. 

    Label[] jumpTable = new Label[] { myIL.DefineLabel(),
                      myIL.DefineLabel(),
                      myIL.DefineLabel(),
                      myIL.DefineLabel(),
                      myIL.DefineLabel() };

    // arg0, the number we passed, is pushed onto the stack.
    // In this case, due to the design of the code sample,
    // the value pushed onto the stack happens to match the
    // index of the label (in IL terms, the index of the offset
    // in the jump table). If this is not the case, such as
    // when switching based on non-integer values, rules for the correspondence
    // between the possible case values and each index of the offsets
    // must be established outside of the ILGenerator.Emit calls,
    // much as a compiler would.

    myIL.Emit(OpCodes.Ldarg_0);
    myIL.Emit(OpCodes.Switch, jumpTable);
    
    // Branch on default case
    myIL.Emit(OpCodes.Br_S, defaultCase);

    // Case arg0 = 0
    myIL.MarkLabel(jumpTable[0]); 
    myIL.Emit(OpCodes.Ldstr, "are no bananas");
    myIL.Emit(OpCodes.Br_S, endOfMethod);

    // Case arg0 = 1
    myIL.MarkLabel(jumpTable[1]); 
    myIL.Emit(OpCodes.Ldstr, "is one banana");
    myIL.Emit(OpCodes.Br_S, endOfMethod);

    // Case arg0 = 2
    myIL.MarkLabel(jumpTable[2]); 
    myIL.Emit(OpCodes.Ldstr, "are two bananas");
    myIL.Emit(OpCodes.Br_S, endOfMethod);

    // Case arg0 = 3
    myIL.MarkLabel(jumpTable[3]); 
    myIL.Emit(OpCodes.Ldstr, "are three bananas");
    myIL.Emit(OpCodes.Br_S, endOfMethod);

    // Case arg0 = 4
    myIL.MarkLabel(jumpTable[4]); 
    myIL.Emit(OpCodes.Ldstr, "are four bananas");
    myIL.Emit(OpCodes.Br_S, endOfMethod);

    // Default case
    myIL.MarkLabel(defaultCase);
    myIL.Emit(OpCodes.Ldstr, "are many bananas");

    myIL.MarkLabel(endOfMethod);
    myIL.Emit(OpCodes.Ret);
    
    return myTypeBuilder.CreateType();

   }

   public static void Main()
   {
    Type myType = BuildMyType();
    
    Console.Write("Enter an integer between 0 and 5: ");
    int theValue = Convert.ToInt32(Console.ReadLine());

    Console.WriteLine("---");
    Object myInstance = Activator.CreateInstance(myType, new object[0]);
    
    Console.WriteLine("Yes, there {0} today!", myType.InvokeMember("SwitchMe"
,
                                 BindingFlags.InvokeMethod,
                                 null,
                                 myInstance,
                                 new object[] {theValue}));  
              
   }

}

using namespace System;
using namespace System::Threading;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
Type^ BuildMyType()
{
   AppDomain^ myDomain = Thread::GetDomain();
   AssemblyName^ myAsmName = gcnew AssemblyName;
   myAsmName->Name = "MyDynamicAssembly";
   AssemblyBuilder^ myAsmBuilder = myDomain->DefineDynamicAssembly( myAsmName,
 AssemblyBuilderAccess::Run );
   ModuleBuilder^ myModBuilder = myAsmBuilder->DefineDynamicModule( "MyJumpTableDemo"
 );
   TypeBuilder^ myTypeBuilder = myModBuilder->DefineType( "JumpTableDemo",
 TypeAttributes::Public );
   array<Type^>^temp0 = {int::typeid};
   MethodBuilder^ myMthdBuilder = myTypeBuilder->DefineMethod( "SwitchMe",
 static_cast<MethodAttributes>(MethodAttributes::Public | MethodAttributes::Static),
 String::typeid, temp0 );
   ILGenerator^ myIL = myMthdBuilder->GetILGenerator();
   Label defaultCase = myIL->DefineLabel();
   Label endOfMethod = myIL->DefineLabel();
   
   // We are initializing our jump table. Note that the labels
   // will be placed later using the MarkLabel method.
   array<Label>^jumpTable = gcnew array<Label>(5);
   jumpTable[ 0 ] = myIL->DefineLabel();
   jumpTable[ 1 ] = myIL->DefineLabel();
   jumpTable[ 2 ] = myIL->DefineLabel();
   jumpTable[ 3 ] = myIL->DefineLabel();
   jumpTable[ 4 ] = myIL->DefineLabel();
   
   // arg0, the number we passed, is pushed onto the stack.
   // In this case, due to the design of the code sample,
   // the value pushed onto the stack happens to match the
   // index of the label (in IL terms, the index of the offset
   // in the jump table). If this is not the case, such as
   // when switching based on non-integer values, rules for the correspondence
   // between the possible case values and each index of the offsets
   // must be established outside of the ILGenerator::Emit calls,
   // much as a compiler would.
   myIL->Emit( OpCodes::Ldarg_0 );
   myIL->Emit( OpCodes::Switch, jumpTable );
   
   // Branch on default case
   myIL->Emit( OpCodes::Br_S, defaultCase );
   
   // Case arg0 = 0
   myIL->MarkLabel( jumpTable[ 0 ] );
   myIL->Emit( OpCodes::Ldstr, "are no bananas" );
   myIL->Emit( OpCodes::Br_S, endOfMethod );
   
   // Case arg0 = 1
   myIL->MarkLabel( jumpTable[ 1 ] );
   myIL->Emit( OpCodes::Ldstr, "is one banana" );
   myIL->Emit( OpCodes::Br_S, endOfMethod );
   
   // Case arg0 = 2
   myIL->MarkLabel( jumpTable[ 2 ] );
   myIL->Emit( OpCodes::Ldstr, "are two bananas" );
   myIL->Emit( OpCodes::Br_S, endOfMethod );
   
   // Case arg0 = 3
   myIL->MarkLabel( jumpTable[ 3 ] );
   myIL->Emit( OpCodes::Ldstr, "are three bananas" );
   myIL->Emit( OpCodes::Br_S, endOfMethod );
   
   // Case arg0 = 4
   myIL->MarkLabel( jumpTable[ 4 ] );
   myIL->Emit( OpCodes::Ldstr, "are four bananas" );
   myIL->Emit( OpCodes::Br_S, endOfMethod );
   
   // Default case
   myIL->MarkLabel( defaultCase );
   myIL->Emit( OpCodes::Ldstr, "are many bananas" );
   myIL->MarkLabel( endOfMethod );
   myIL->Emit( OpCodes::Ret );
   return myTypeBuilder->CreateType();
}

int main()
{
   Type^ myType = BuildMyType();
   Console::Write( "Enter an integer between 0 and 5: " );
   int theValue = Convert::ToInt32( Console::ReadLine() );
   Console::WriteLine( "---" );
   Object^ myInstance = Activator::CreateInstance( myType, gcnew array<Object^>(0)
 );
   array<Object^>^temp1 = {theValue};
   Console::WriteLine( "Yes, there {0} today!", myType->InvokeMember(
 "SwitchMe", BindingFlags::InvokeMethod, nullptr, myInstance, temp1 )
 );
}

import System .* ;
import System.Threading .* ;
import System.Reflection .* ;
import System.Reflection.Emit .* ;

class DynamicJumpTableDemo
{
    public static Type BuildMyType()
    {
        AppDomain myDomain = System.Threading.Thread.GetDomain();
        AssemblyName myAsmName = new AssemblyName();
        myAsmName.set_Name("MyDynamicAssembly");
        AssemblyBuilder myAsmBuilder = myDomain.DefineDynamicAssembly
            (myAsmName, AssemblyBuilderAccess.Run);
        ModuleBuilder myModBuilder = myAsmBuilder.DefineDynamicModule
            ("MyJumpTableDemo");
        TypeBuilder myTypeBuilder = myModBuilder.DefineType("JumpTableDemo"
,
            TypeAttributes.Public);
        MethodBuilder myMthdBuilder = myTypeBuilder.DefineMethod("SwitchMe"
,
            MethodAttributes.Public | MethodAttributes.Static,
            String.class.ToType(),new Type[]
 { int.class.ToType() });
        ILGenerator myIL = myMthdBuilder.GetILGenerator();
        Label defaultCase = myIL.DefineLabel();
        Label endOfMethod = myIL.DefineLabel();

        // We are initializing our jump table. Note that the labels
        // will be placed later using the MarkLabel method. 
        Label jumpTable[] = new Label[] { myIL.DefineLabel(),
            myIL.DefineLabel(), myIL.DefineLabel(), myIL.DefineLabel(),
            myIL.DefineLabel() };

        // arg0, the number we passed, is pushed onto the stack.
        // In this case, due to the design of the code sample,
        // the value pushed onto the stack happens to match the
        // index of the label (in IL terms, the index of the offset
        // in the jump table). If this is not the case, such as
        // when switching based on non-integer values, rules for the
 
        // correspondence between the possible case values and each
 index 
        // of the offsets must be established outside of the ILGenerator.
        // Emit calls, much as a compiler would.
        myIL.Emit(OpCodes.Ldarg_0);
        myIL.Emit(OpCodes.Switch, jumpTable);

        // Branch on default case
        myIL.Emit(OpCodes.Br_S, defaultCase);

        // Case arg0 = 0
        myIL.MarkLabel(jumpTable[0]);
        myIL.Emit(OpCodes.Ldstr, "are no bananas");
        myIL.Emit(OpCodes.Br_S, endOfMethod);

        // Case arg0 = 1
        myIL.MarkLabel(jumpTable[1]);
        myIL.Emit(OpCodes.Ldstr, "is one banana");
        myIL.Emit(OpCodes.Br_S, endOfMethod);

        // Case arg0 = 2
        myIL.MarkLabel(jumpTable[2]);
        myIL.Emit(OpCodes.Ldstr, "are two bananas");
        myIL.Emit(OpCodes.Br_S, endOfMethod);

        // Case arg0 = 3
        myIL.MarkLabel(jumpTable[3]);
        myIL.Emit(OpCodes.Ldstr, "are three bananas");
        myIL.Emit(OpCodes.Br_S, endOfMethod);

        // Case arg0 = 4
        myIL.MarkLabel(jumpTable[4]);
        myIL.Emit(OpCodes.Ldstr, "are four bananas");
        myIL.Emit(OpCodes.Br_S, endOfMethod);

        // Default case
        myIL.MarkLabel(defaultCase);
        myIL.Emit(OpCodes.Ldstr, "are many bananas");
        myIL.MarkLabel(endOfMethod);
        myIL.Emit(OpCodes.Ret);
        return myTypeBuilder.CreateType();
    } //BuildMyType    
   
   public static void main(String[]
 args)
   {
        Type myType = BuildMyType();
        Console.Write("Enter an integer between 0 and 5: ");
        int theValue = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("---");
        Object myInstance = Activator.CreateInstance(myType,new
 Object[0]);
        Console.WriteLine("Yes, there {0} today!",
            myType.InvokeMember("SwitchMe", BindingFlags.InvokeMethod,
            null, myInstance, new Object[]{(Int32)(theValue)}));
    } //main
} //DynamicJumpTableDemo
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.Emit メソッド (OpCode, Single)

命令MSIL (Microsoft Intermediate Language) ストリームに、指定した命令数値引数書き込みます

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overridable Sub Emit
 ( _
    opcode As OpCode, _
    arg As Single _
)
Dim instance As ILGenerator
Dim opcode As OpCode
Dim arg As Single

instance.Emit(opcode, arg)
public virtual void Emit (
    OpCode opcode,
    float arg
)
public:
virtual void Emit (
    OpCode opcode, 
    float arg
)
public void Emit (
    OpCode opcode, 
    float arg
)
public function Emit (
    opcode : OpCode, 
    arg : float
)

パラメータ

opcode

ストリーム書き込む MSIL (Microsoft intermediate language) 命令

arg

命令直後ストリーム格納する Single 引数

解説解説

この命令値は、OpCodes 列挙体で定義されている値にします。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からILGenerator.Emitを検索した結果を表示しています。
Weblioに収録されているすべての辞書からILGenerator.Emitを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からILGenerator.Emit を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ILGenerator.Emit」の関連用語

ILGenerator.Emitのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ILGenerator.Emitのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS