>
> Hey,
>
> On Sun, Nov 7, 2010 at 3:08 PM, kostaz <[email protected]> wrote:
> > According to Cecil FAQ (http://www.mono-project.com/Cecil:FAQ), the
> > below code "will insert the following code into *each* methods of
> > *each* type of the assembly":
>
> Note that this FAQ hasn't been updated to Cecil 0.9, that you should get
> from:
>
> http://github.com/jbevain/cecil
>
> You can read some HOWTO on the wiki there.
>
> > Two questions:
> > (1) What about another 'foreach' for all assembly.Modules:
> >    foreach (ModuleDefinition module in assembly.Modules)
> >        foreach (TypeDefinition type in module.Types)
>
> If you want to be thorough, yes. However, multi module assemblies are
> rare (VS doesn't know how to deal with them), most of the time you'll
> work with assemblies with one manifest module.
>

Ok, got it. I just run the below code out of curiosity:
-----------------
string filePath = "C:/Program Files/Reference
Assemblies/Microsoft/Framework/v3.5/System.Core.dll";
AssemblyDefinition asm = AssemblyFactory.GetAssembly(filePath);
Console.WriteLine("MainModule.Name = \n\t" + asm.MainModule.ToString());
foreach (ModuleDefinition module in asm.Modules)
    Console.WriteLine("module.Name = \n\t" + module.ToString());

The run results:
-----------------
C:\...\bin\Release>ModulesPrinter.exe
MainModule.Name =
        (main), Mvid=d7f19ba4-0112-4fd4-aff1-636a620526f2
module.Name =
        (main), Mvid=d7f19ba4-0112-4fd4-aff1-636a620526f2

Am I right to conclude that:
    single-manifest assembly module (from Microsoft .NET Framework) will
always have its MainModule equal to its only one module in asm.Modules?
Can you give some example of well established project (Windows-based or not)
that uses multi-manifest assembly module?


> > (2) What is it the peculiar type.Name "<Module>"? Should we *always*
> > skip it when working with Cecil?
>
> It depends on what you want to achieve. The <Module> type is a special
> type which has to be the first type of the assembly, and it's supposed
> to hold «global methods and global fields» (read static fields and
> static methods). Some compiler emit methods and fields there, you
> might want to deal with them as well.
>
> Thanks, got it.

-- 
--
mono-cecil

Reply via email to