什么是“<模块>”?类型? [英] What is the "<Module>" type?

查看:246
本文介绍了什么是“<模块>”?类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Mono.Cecil读取 Regex.CompileToAssembly()生成的程序集。当我遍历这些类型时,根名称空间中有一种名为< Module> 的类型。该类型没有基本类型。这是什么类型这是某些Mono.Cecil工件还是实际上是.NET程序集的一部分?

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 named <Module>. The type has no base type. What is this type? Is this some Mono.Cecil artifact or something that is actually a real part of .NET assemblies? What role does it play?

推荐答案

< Module> 类型是不适合CLI模型的声明的占位符。通常仅在混合模式的程序集中相关,既包含以托管语言编写的代码,也包含非托管代码(如C或C ++)。对于纯托管程序集,该字段为空。

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.

这些语言支持自由函数和全局变量。 CLR不直接支持这一点,方法和变量必须始终是类型的成员。因此,元数据生成器使用一个简单的技巧,它将创建一个假类型作为此类函数和变量的宿主。该假类型的名称为< Module> 。它始终具有内部可访问性来隐藏成员。这些类型中只有一种,其RID始终为1。

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.

CLR源代码将其称为全局类。

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

这篇关于什么是“&lt;模块&gt;”?类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆