What is the “” type?

后端 未结 1 558
南旧
南旧 2021-01-18 15:33

I am using Mono.Cecil to read an assembly generated by Regex.CompileToAssembly(). When I iterate through the types, there is one type in the root namespace name

相关标签:
1条回答
  • 2021-01-18 16:15

    The <Module> type is a place-holder for declarations that do not fit the CLI model. Normally relevant only in assemblies that are mixed-mode, containing both code written in a managed language as well as an unmanaged one like C or C++. It is empty for pure managed assemblies.

    Those languages support free functions and global variables. The CLR does not directly support that, methods and variables must always be a member of a type. So the metadata generator uses a simple trick, it creates a fake type to be the home of such functions and variables. The name of that fake type is <Module>. It always has internal accessibility to hide the members. There is only ever one of those types, its RID is always 1.

    The CLR source code calls it the "Global Class".

    0 讨论(0)
提交回复
热议问题