什么时候存在什么规则!T被使用vs!0?

我正在编写一个IL静态分析工具,并且我很难理解如何引用泛型类型参数的规则:

取这个IL(来自IList<T>界面):

.property instance !T Item(
    int32 index
)
{
    .get instance !0 System.Collections.Generic.IList`1::get_Item(int32)
    .set instance void System.Collections.Generic.IList`1::set_Item(int32, !0)
}

为什么!0代替!T ? 我认为它们与虚拟机的功能是等价的,只要保证名称的存在,使用位置引用就显得很奇怪。

更新:来自KeyedCollection.ctor的其他案例:

IL_0037:  newobj instance void class System.Collections.Generic.Dictionary`2<!TKey,!TItem>::'.ctor'(class System.Collections.Generic.IEqualityComparer`1<!0>)
IL_003c:  stfld class System.Collections.Generic.Dictionary`2<!0,!1> class System.Collections.ObjectModel.KeyedCollection`2<!0,!1>::dictionary

在通用语言基础结构标准“分区II - 元数据和文件格式”第7.1节“类型”中指出:

Type ::=        Description
--------        -----------
'!'             Generic parameter in a type definition, accessed by index from 0

这么简短的回答:因为它在规范中。

长答案:这是我的猜测,但基本上,大多数IL命令是基于堆栈的,并始终使用位置参考作为参数。 也就是说,为了维护IL中的常见模式/使用机制,位置引用被用于泛型是有意义的。

链接地址: http://www.djcxy.com/p/61547.html

上一篇: what rules exist for when !T is used vs !0?

下一篇: What URLs on an https page need to be https?