我寫的IL靜態分析工具,我有一個很難理解如何管理泛型類型參數引用的規則:IL泛型 - 什麼時候存在什麼規則!T被使用vs!0?
藉此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
?我認爲它們與虛擬機的功能是等價的,只要保證名稱的存在,使用位置引用就顯得很奇怪。
更新:額外的情況下,從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
我看不到這個。你確定它不僅僅是你的反彙編程序中的一個bug嗎? – 2012-07-13 20:36:41
嗯,這絕對是反彙編器(在這種情況下monodis)正在產生的東西。 Mono.Cecil(它看起來更像書中的元數據),例如:stfld System.Collections.Generic.Dictionary'2 System.Collections.ObjectModel.KeyedCollection'2 :: dictionary –
toshok
2012-07-13 22:41:07
@HansPassant你用什麼來向你展示IL? – casperOne 2012-07-14 01:41:05