什么是“<模块>"?类型? [英] What is the &quot;&lt;Module&gt;&quot; type?

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

问题描述

我正在使用 Mono.Cecil 读取由 Regex.CompileToAssembly() 生成的程序集.当我遍历类型时,在名为 的根命名空间中有一种类型.该类型没有基类型.这是什么类型?这是一些 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?

推荐答案

类型是不适合 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 不直接支持方法和变量必须始终是类型的成员.所以元数据生成器使用了一个简单的技巧,它创建了一个假类型作为这些函数和变量的家.该假类型的名称是 .它始终具有内部可访问性来隐藏成员.这些类型中只有一种,其 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".

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

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