【发布时间】:2012-07-13 18:06:50
【问题描述】:
我正在编写一个 IL 静态分析工具,但我很难理解管理如何引用泛型类型参数的规则:
获取此 IL(来自 IList<T> interface):
.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?我认为就 VM 而言它们是等价的,但在保证有名称的情况下使用位置引用似乎很奇怪。
更新:另一个案例,来自 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
【问题讨论】:
-
我没有看到这个。你确定这不仅仅是你的反汇编程序中的一个错误吗?
-
嗯,这绝对是反汇编程序(在本例中为 monodis)正在生成的东西。 Mono.Cecil (这似乎更符合书籍元数据)显示,例如:stfld System.Collections.Generic.Dictionary
2<TKey,TItem> System.Collections.ObjectModel.KeyedCollection2::dictionary -
@HansPassant 你用什么来向你展示 IL?