MethodBuilder.GetModule 方法

返回对包含此方法的模块的引用。

**命名空间:**System.Reflection.Emit
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public Function GetModule As Module
用法
Dim instance As MethodBuilder
Dim returnValue As Module

returnValue = instance.GetModule
public Module GetModule ()
public:
Module^ GetModule ()
public Module GetModule ()
public function GetModule () : Module

返回值

返回对包含此方法的模块的引用。

示例

下面的代码示例演示了如何使用 GetModule 方法检索有关动态生成模块的信息。

Dim myModBuilder As ModuleBuilder = myAsmBuilder.DefineDynamicModule("MathFunctions")

Dim myTypeBuilder As TypeBuilder = myModBuilder.DefineType("MyMathFunctions", _
                          TypeAttributes.Public)

Dim myMthdBuilder As MethodBuilder = myTypeBuilder.DefineMethod("Adder", _
              MethodAttributes.Public, GetType(Integer), _
              New Type() {GetType(Integer), GetType(Integer)})

' Create body via ILGenerator here ...

Dim myNewType As Type = myTypeBuilder.CreateType()

Dim myModule As [Module] = myMthdBuilder.GetModule()

Dim myModTypes As Type() = myModule.GetTypes()
Console.WriteLine("Module: {0}", myModule.Name)
Console.WriteLine("------- with path {0}", myModule.FullyQualifiedName)
Console.WriteLine("------- in assembly {0}", myModule.Assembly.FullName)
Dim myModType As Type
For Each myModType In  myModTypes
   Console.WriteLine("------- has type {0}", myModType.FullName)
Next myModType
ModuleBuilder myModBuilder = myAsmBuilder.DefineDynamicModule("MathFunctions");

TypeBuilder myTypeBuilder = myModBuilder.DefineType("MyMathFunctions",
                TypeAttributes.Public);

MethodBuilder myMthdBuilder = myTypeBuilder.DefineMethod("Adder",
                MethodAttributes.Public,
                typeof(int),
                new Type[] { typeof(int),
                         typeof(int) });

// Create body via ILGenerator here ...

Type myNewType = myTypeBuilder.CreateType();

Module myModule = myMthdBuilder.GetModule();

 Type[] myModTypes = myModule.GetTypes();
Console.WriteLine("Module: {0}", myModule.Name);
Console.WriteLine("------- with path {0}", myModule.FullyQualifiedName);
Console.WriteLine("------- in assembly {0}", myModule.Assembly.FullName);
foreach (Type myModType in myModTypes)
    {
    Console.WriteLine("------- has type {0}", myModType.FullName);
}
      ModuleBuilder^ myModBuilder = myAsmBuilder->DefineDynamicModule( "MathFunctions" );
      TypeBuilder^ myTypeBuilder = myModBuilder->DefineType( "MyMathFunctions", TypeAttributes::Public );
      array<Type^>^temp0 = {int::typeid,int::typeid};
      MethodBuilder^ myMthdBuilder = myTypeBuilder->DefineMethod( "Adder", MethodAttributes::Public, int::typeid, temp0 );
      
      // Create body via ILGenerator here ...
      Type^ myNewType = myTypeBuilder->CreateType();
      Module^ myModule = myMthdBuilder->GetModule();
      array<Type^>^myModTypes = myModule->GetTypes();
      Console::WriteLine( "Module: {0}", myModule->Name );
      Console::WriteLine( "------- with path {0}", myModule->FullyQualifiedName );
      Console::WriteLine( "------- in assembly {0}", myModule->Assembly->FullName );
      System::Collections::IEnumerator^ myEnum = myModTypes->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         Type^ myModType = safe_cast<Type^>(myEnum->Current);
         Console::WriteLine( "------- has type {0}", myModType->FullName );
      }
   }

};
ModuleBuilder myModBuilder = myAsmBuilder.DefineDynamicModule(
    "MathFunctions");
TypeBuilder myTypeBuilder = myModBuilder.DefineType("MyMathFunctions",
    TypeAttributes.Public);
MethodBuilder myMthdBuilder = myTypeBuilder.DefineMethod("Adder",
    MethodAttributes.Public,int.class.ToType(),
    new Type[] { int.class.ToType(),int.class.ToType() });

// Create body via ILGenerator here ...
Type myNewType = myTypeBuilder.CreateType();
Module myModule = myMthdBuilder.GetModule();
Type myModTypes[] = myModule.GetTypes();

Console.WriteLine("Module: {0}", myModule.get_Name());
Console.WriteLine("------- with path {0}", 
    myModule.get_FullyQualifiedName());
Console.WriteLine("------- in assembly {0}",
    myModule.get_Assembly().get_FullName());
for (int iCtr = 0; iCtr < myModTypes.length; iCtr++) {
    Type myModType = myModTypes[iCtr];
    Console.WriteLine("------- has type {0}",myModType.get_FullName());
}

平台

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 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

MethodBuilder 类
MethodBuilder 成员
System.Reflection.Emit 命名空间