Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
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()

Return Value

Type: System.Reflection::Module
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 );
      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 );
      }
   }

};

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft