Export (0) Print
Expand All

MethodBuilder.GetModule Method

Returns a reference to the module that contains this method.

Namespace: System.Reflection.Emit
Assembly: mscorlib (in mscorlib.dll)

public Module GetModule ()
public Module GetModule ()
public function GetModule () : Module
Not applicable.

Return Value

Returns a reference to the module that contains this method.

The sample code below illustrates the usage of the GetModule method to retrieve information about a dynamically-generated module.

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);
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 Server 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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft