I know, I know. Macros are evil. So just FYI, with those:

 

#define FOR_EACH( ___T, ___V, ___C ) \

               ___T * ___V ; \

               Enumerator<___T> __enum_##___V(___C) ; \

               while ( (__enum_##___V).MoveNext() ? ( ___V = __enum_##___V.get_Current() , true): false )

 

#define FOR_EACHV( ___T, ___V, ___C ) \

               ___T __box * ___V ; \

               ValueEnumerator<___T> __enum_##___V(___C) ; \

               while ( (__enum_##___V).MoveNext() ? ( ___V = __enum_##___V.get_Current() , true): false )

 

You can write:

 

FOR_EACH( Module, m, Assembly::GetExecutingAssembly()->GetModules() )

{

   Console::WriteLine( S"\n\nTypes of module {0}:", m->Name ) ;

   FOR_EACH( Type, t, m->GetTypes() )

      Console::WriteLine( S"{0}", t->Name ) ;

 

   Console::WriteLine( S"\n\nMethods of module {0}:", m->Name ) ;

   FOR_EACH( MethodInfo, mi, m->GetMethods() )

      Console::WriteLine( S"{0}", mi->Name ) ;

 

   Console::WriteLine( S"\n\nFields of module {0}:", m->Name ) ;

   FOR_EACH( FieldInfo, fi, m->GetFields() )

      Console::WriteLine( S"{0}", fi->Name ) ;

}

 

Int32 ai __gc [] = { 1, 2, 3, 4 } ;

FOR_EACHV( Int32, i, ai )

   Console::WriteLine( S"{0}", i->ToString() ) ;