What is the type of <Module>?

I am using Mono.Cecil to read the assembly generated by Regex.CompileToAssembly() . When I repeat the types, there is one type in the root namespace called <Module> . A type does not have a base type. What type is this? Is this some kind of Mono.Cecil artifact or something that is actually part of the .NET collections? What role does he play?

+5
source share
1 answer

The <Module> is a place holder for declarations that do not match the CLI model. Normally relevant only in mixed-mode assemblies containing both code written in a managed language and unmanaged, such as C or C ++. It is empty for clean, managed assemblies.

These languages ​​support free functions and global variables. The CLR does not directly support this; methods and variables should always be type members. Thus, the metadata generator uses a simple trick, it creates a fake type that will become home to such functions and variables. The name of this fake type is <Module> . It always has internal accessibility to hide participants. There is only one of these types; its RID is always 1.

The CLR source code calls it the "global class".

+7
source

Source: https://habr.com/ru/post/1243806/


All Articles