ModuleBuilder クラス
アセンブリ: mscorlib (mscorlib.dll 内)

<ComVisibleAttribute(True)> _ <ClassInterfaceAttribute(ClassInterfaceType.None)> _ Public Class ModuleBuilder Inherits Module Implements _ModuleBuilder
[ComVisibleAttribute(true)] [ClassInterfaceAttribute(ClassInterfaceType.None)] public class ModuleBuilder : Module, _ModuleBuilder
[ComVisibleAttribute(true)] [ClassInterfaceAttribute(ClassInterfaceType::None)] public ref class ModuleBuilder : public Module, _ModuleBuilder

![]() |
---|
このクラスに適用される HostProtectionAttribute 属性の Resources プロパティの値は、MayLeakOnAbort です。HostProtectionAttribute は、デスクトップ アプリケーション (一般的には、アイコンをダブルクリック、コマンドを入力、またはブラウザに URL を入力して起動するアプリケーション) には影響しません。詳細については、HostProtectionAttribute クラスのトピックまたは「SQL Server プログラミングとホスト保護属性」を参照してください。 |

次のコード例は、ModuleBuilder を使用して、動的モジュールを作成する方法を示しています。ModuleBuilder は、コンストラクタではなく、AssemblyBuilder の DefineDynamicModule の呼び出しによって作成されます。
Imports System Imports System.Reflection Imports System.Reflection.Emit Imports System.Security.Permissions Public Class CodeGenerator Private myAssemblyBuilder As AssemblyBuilder Public Sub New() ' Get the current application domain for the current thread. Dim myCurrentDomain As AppDomain = AppDomain.CurrentDomain Dim myAssemblyName As New AssemblyName() myAssemblyName.Name = "TempAssembly" ' Define a dynamic assembly in the current application domain. myAssemblyBuilder = _ myCurrentDomain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Run) ' Define a dynamic module in this assembly. Dim myModuleBuilder As ModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule") ' Define a runtime class with specified name and attributes. Dim myTypeBuilder As TypeBuilder = _ myModuleBuilder.DefineType("TempClass", TypeAttributes.Public) ' Add 'Greeting' field to the class, with the specified attribute and type. Dim greetingField As FieldBuilder = _ myTypeBuilder.DefineField("Greeting", GetType(String), FieldAttributes.Public) Dim myMethodArgs As Type() = {GetType(String)} ' Add 'MyMethod' method to the class, with the specified attribute and signature. Dim myMethod As MethodBuilder = _ myTypeBuilder.DefineMethod("MyMethod", MethodAttributes.Public, _ CallingConventions.Standard, Nothing, myMethodArgs) Dim methodIL As ILGenerator = myMethod.GetILGenerator() methodIL.EmitWriteLine("In the method...") methodIL.Emit(OpCodes.Ldarg_0) methodIL.Emit(OpCodes.Ldarg_1) methodIL.Emit(OpCodes.Stfld, greetingField) methodIL.Emit(OpCodes.Ret) myTypeBuilder.CreateType() End Sub 'New Public ReadOnly Property MyAssembly() As AssemblyBuilder Get Return Me.myAssemblyBuilder End Get End Property End Class 'CodeGenerator Public Class TestClass <PermissionSetAttribute(SecurityAction.Demand, Name:="FullTrust")> _ Public Shared Sub Main() Dim myCodeGenerator As New CodeGenerator() ' Get the assembly builder for 'myCodeGenerator' object. Dim myAssemblyBuilder As AssemblyBuilder = myCodeGenerator.MyAssembly ' Get the module builder for the above assembly builder object . Dim myModuleBuilder As ModuleBuilder = myAssemblyBuilder.GetDynamicModule("TempModule") Console.WriteLine("The fully qualified name and path to this " + _ "module is :" + myModuleBuilder.FullyQualifiedName) Dim myType As Type = myModuleBuilder.GetType("TempClass") Dim myMethodInfo As MethodInfo = myType.GetMethod("MyMethod") ' Get the token used to identify the method within this module. Dim myMethodToken As MethodToken = myModuleBuilder.GetMethodToken(myMethodInfo) Console.WriteLine("Token used to identify the method of 'myType'" + _ " within the module is {0:x}", myMethodToken.Token) Dim args As Object() = {"Hello."} Dim myObject As Object = Activator.CreateInstance(myType, Nothing, Nothing) myMethodInfo.Invoke(myObject, args) End Sub 'Main End Class 'TestClass
using System; using System.Reflection; using System.Reflection.Emit; using System.Security.Permissions; public class CodeGenerator { AssemblyBuilder myAssemblyBuilder; public CodeGenerator() { // Get the current application domain for the current thread. AppDomain myCurrentDomain = AppDomain.CurrentDomain; AssemblyName myAssemblyName = new AssemblyName(); myAssemblyName.Name = "TempAssembly"; // Define a dynamic assembly in the current application domain. myAssemblyBuilder = myCurrentDomain.DefineDynamicAssembly (myAssemblyName, AssemblyBuilderAccess.Run); // Define a dynamic module in this assembly. ModuleBuilder myModuleBuilder = myAssemblyBuilder. DefineDynamicModule("TempModule"); // Define a runtime class with specified name and attributes. TypeBuilder myTypeBuilder = myModuleBuilder.DefineType ("TempClass",TypeAttributes.Public); // Add 'Greeting' field to the class, with the specified attribute and type. FieldBuilder greetingField = myTypeBuilder.DefineField("Greeting", typeof(String), FieldAttributes.Public); Type[] myMethodArgs = { typeof(String) }; // Add 'MyMethod' method to the class, with the specified attribute and signature. MethodBuilder myMethod = myTypeBuilder.DefineMethod("MyMethod", MethodAttributes.Public, CallingConventions.Standard, null ,myMethodArgs); ILGenerator methodIL = myMethod.GetILGenerator(); methodIL.EmitWriteLine("In the method..."); methodIL.Emit(OpCodes.Ldarg_0); methodIL.Emit(OpCodes.Ldarg_1); methodIL.Emit(OpCodes.Stfld, greetingField); methodIL.Emit(OpCodes.Ret); myTypeBuilder.CreateType(); } public AssemblyBuilder MyAssembly { get { return this.myAssemblyBuilder; } } } public class TestClass { [PermissionSetAttribute(SecurityAction.Demand, Name="FullTrust")] public static void Main() { CodeGenerator myCodeGenerator = new CodeGenerator(); // Get the assembly builder for 'myCodeGenerator' object. AssemblyBuilder myAssemblyBuilder = myCodeGenerator.MyAssembly; // Get the module builder for the above assembly builder object . ModuleBuilder myModuleBuilder = myAssemblyBuilder. GetDynamicModule("TempModule"); Console.WriteLine("The fully qualified name and path to this " + "module is :" +myModuleBuilder.FullyQualifiedName); Type myType = myModuleBuilder.GetType("TempClass"); MethodInfo myMethodInfo = myType.GetMethod("MyMethod"); // Get the token used to identify the method within this module. MethodToken myMethodToken = myModuleBuilder.GetMethodToken(myMethodInfo); Console.WriteLine("Token used to identify the method of 'myType'" + " within the module is {0:x}",myMethodToken.Token); object[] args={"Hello."}; object myObject = Activator.CreateInstance(myType,null,null); myMethodInfo.Invoke(myObject,args); } }
using namespace System; using namespace System::Reflection; using namespace System::Reflection::Emit; public ref class CodeGenerator { private: AssemblyBuilder^ myAssemblyBuilder; public: CodeGenerator() { // Get the current application domain for the current thread. AppDomain^ myCurrentDomain = AppDomain::CurrentDomain; AssemblyName^ myAssemblyName = gcnew AssemblyName; myAssemblyName->Name = "TempAssembly"; // Define a dynamic assembly in the current application domain. myAssemblyBuilder = myCurrentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run ); // Define a dynamic module in this assembly. ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule" ); // Define a runtime class with specified name and attributes. TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "TempClass", TypeAttributes::Public ); // Add 'Greeting' field to the class, with the specified attribute and type. FieldBuilder^ greetingField = myTypeBuilder->DefineField( "Greeting", String::typeid, FieldAttributes::Public ); array<Type^>^myMethodArgs = {String::typeid}; // Add 'MyMethod' method to the class, with the specified attribute and signature. MethodBuilder^ myMethod = myTypeBuilder->DefineMethod( "MyMethod", MethodAttributes::Public, CallingConventions::Standard, nullptr, myMethodArgs ); ILGenerator^ methodIL = myMethod->GetILGenerator(); methodIL->EmitWriteLine( "In the method..." ); methodIL->Emit( OpCodes::Ldarg_0 ); methodIL->Emit( OpCodes::Ldarg_1 ); methodIL->Emit( OpCodes::Stfld, greetingField ); methodIL->Emit( OpCodes::Ret ); myTypeBuilder->CreateType(); } property AssemblyBuilder^ MyAssembly { AssemblyBuilder^ get() { return this->myAssemblyBuilder; } } }; int main() { CodeGenerator^ myCodeGenerator = gcnew CodeGenerator; // Get the assembly builder for 'myCodeGenerator' object. AssemblyBuilder^ myAssemblyBuilder = myCodeGenerator->MyAssembly; // Get the module builder for the above assembly builder object . ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->GetDynamicModule( "TempModule" ); Console::WriteLine( "The fully qualified name and path to this module is :{0}", myModuleBuilder->FullyQualifiedName ); Type^ myType = myModuleBuilder->GetType( "TempClass" ); MethodInfo^ myMethodInfo = myType->GetMethod( "MyMethod" ); // Get the token used to identify the method within this module. MethodToken myMethodToken = myModuleBuilder->GetMethodToken( myMethodInfo ); Console::WriteLine( "Token used to identify the method of 'myType'" " within the module is {0:x}", myMethodToken.Token ); array<Object^>^args = {"Hello."}; Object^ myObject = Activator::CreateInstance( myType, nullptr, nullptr ); myMethodInfo->Invoke( myObject, args ); }

System.Reflection.Module
System.Reflection.Emit.ModuleBuilder


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ModuleBuilder プロパティ

名前 | 説明 | |
---|---|---|
![]() | Assembly | Module のこのインスタンスの適切な Assembly を取得します。 ( Module から継承されます。) |
![]() | FullyQualifiedName | オーバーライドされます。 このモジュールの完全修飾名とパスを表す文字列を取得します。 |
![]() | MDStreamVersion | メタデータ ストリームのバージョンを取得します。 ( Module から継承されます。) |
![]() | MetadataToken | メタデータ内のモジュールを識別するトークンを取得します。 ( Module から継承されます。) |
![]() | ModuleHandle | モジュールのハンドルを取得します。 ( Module から継承されます。) |
![]() | ModuleVersionId | モジュールの 2 つのバージョンを区別するために使用できる汎用一意識別子 (UUID: Universally Unique Identifier) を取得します。 ( Module から継承されます。) |
![]() | Name | モジュールの名前をパスを削除した状態で表す文字列を取得します。 ( Module から継承されます。) |
![]() | ScopeName | モジュールの名前を表す文字列を取得します。 ( Module から継承されます。) |

ModuleBuilder メソッド


名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | GetMethodImpl | 指定した基準に一致するメソッド実装を返します。 ( Module から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | System.Runtime.InteropServices._ModuleBuilder.GetIDsOfNames | 一連の名前を対応する一連のディスパッチ識別子に割り当てます。 |
![]() | System.Runtime.InteropServices._ModuleBuilder.GetTypeInfo | オブジェクトの型情報を取得します。その後は、インターフェイスの型情報の取得に使用できます。 |
![]() | System.Runtime.InteropServices._ModuleBuilder.GetTypeInfoCount | オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。 |
![]() | System.Runtime.InteropServices._ModuleBuilder.Invoke | オブジェクトが公開するプロパティおよびメソッドにアクセスできるようにします。 |

ModuleBuilder メンバ
モジュールを定義および表現します。DefineDynamicModule を呼び出して、ModuleBuilder のインスタンスを取得します。
ModuleBuilder データ型で公開されるメンバを以下の表に示します。

名前 | 説明 | |
---|---|---|
![]() | Assembly | Module のこのインスタンスの適切な Assembly を取得します。(Module から継承されます。) |
![]() | FullyQualifiedName | オーバーライドされます。 このモジュールの完全修飾名とパスを表す文字列を取得します。 |
![]() | MDStreamVersion | メタデータ ストリームのバージョンを取得します。(Module から継承されます。) |
![]() | MetadataToken | メタデータ内のモジュールを識別するトークンを取得します。(Module から継承されます。) |
![]() | ModuleHandle | モジュールのハンドルを取得します。(Module から継承されます。) |
![]() | ModuleVersionId | モジュールの 2 つのバージョンを区別するために使用できる汎用一意識別子 (UUID: Universally Unique Identifier) を取得します。(Module から継承されます。) |
![]() | Name | モジュールの名前をパスを削除した状態で表す文字列を取得します。(Module から継承されます。) |
![]() | ScopeName | モジュールの名前を表す文字列を取得します。(Module から継承されます。) |


名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | GetMethodImpl | 指定した基準に一致するメソッド実装を返します。 (Module から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | System.Runtime.InteropServices._ModuleBuilder.GetIDsOfNames | 一連の名前を対応する一連のディスパッチ識別子に割り当てます。 |
![]() | System.Runtime.InteropServices._ModuleBuilder.GetTypeInfo | オブジェクトの型情報を取得します。その後は、インターフェイスの型情報の取得に使用できます。 |
![]() | System.Runtime.InteropServices._ModuleBuilder.GetTypeInfoCount | オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。 |
![]() | System.Runtime.InteropServices._ModuleBuilder.Invoke | オブジェクトが公開するプロパティおよびメソッドにアクセスできるようにします。 |

_ModuleBuilder インターフェイス
アセンブリ: mscorlib (mscorlib.dll 内)

<CLSCompliantAttribute(False)> _ <GuidAttribute("D05FFA9A-04AF-3519-8EE1-8D93AD73430B")> _ <ComVisibleAttribute(True)> _ <InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _ Public Interface _ModuleBuilder
[CLSCompliantAttribute(false)] [GuidAttribute("D05FFA9A-04AF-3519-8EE1-8D93AD73430B")] [ComVisibleAttribute(true)] [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] public interface _ModuleBuilder
[CLSCompliantAttribute(false)] [GuidAttribute(L"D05FFA9A-04AF-3519-8EE1-8D93AD73430B")] [ComVisibleAttribute(true)] [InterfaceTypeAttribute(ComInterfaceType::InterfaceIsIUnknown)] public interface class _ModuleBuilder


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


_ModuleBuilder メソッド

名前 | 説明 | |
---|---|---|
![]() | GetIDsOfNames | 一連の名前を対応する一連のディスパッチ識別子に割り当てます。 |
![]() | GetTypeInfo | オブジェクトの型情報を取得します。その後は、インターフェイスの型情報の取得に使用できます。 |
![]() | GetTypeInfoCount | オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。 |
![]() | Invoke | オブジェクトが公開するプロパティおよびメソッドにアクセスできるようにします。 |

_ModuleBuilder メンバ
System.Reflection.Emit.ModuleBuilder クラスをアンマネージ コードに公開します。
_ModuleBuilder データ型で公開されるメンバを以下の表に示します。

名前 | 説明 | |
---|---|---|
![]() | GetIDsOfNames | 一連の名前を対応する一連のディスパッチ識別子に割り当てます。 |
![]() | GetTypeInfo | オブジェクトの型情報を取得します。その後は、インターフェイスの型情報の取得に使用できます。 |
![]() | GetTypeInfoCount | オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。 |
![]() | Invoke | オブジェクトが公開するプロパティおよびメソッドにアクセスできるようにします。 |

- _ModuleBuilderのページへのリンク