在许多MSIL列表中,我观察到以下情况:
System.Nullable`1<!0> etc ...
或
class !0 etc ...
在这种情况下,!0
是什么意思?
在许多MSIL列表中,我观察到以下情况:
System.Nullable`1<!0> etc ...
或
class !0 etc ...
在这种情况下,!0
是什么意思?
这是你用来查看文件的反编译器的怪癖.网络组装.这是ildasm的行为.exe,其他像Reflector或ILSpy这样的软件都能做到这一点.编写它的微软程序员采用了一种快捷方式,他从IL生成了一个字符串,该字符串只显示类型参数的编码方式,而没有编写extra代码来查找元数据中的类型参数名称.
You need to read !n
as the n-th type argument of the generic type. Where !0 means "first type argument", !1 means "second type argument", etcetera. For Nullable<>, you know that '!0` means 'T' from the MSDN article.
您也可能会遇到类似于!!T
的情况.两个感叹号表示泛型method的类型参数.这一次,ildasm.exe does查找类型参数名称,而不是使用!!0
.为什么程序员在泛型类型上走捷径,而不是在泛型方法上走捷径,这是很难进行反向工程的.Ildasm是一个相当古怪的程序,它是用C++编码风格编写的,与.NET中的其他C++代码非常不同.这不是很有规律的,不可能是实习生的作业(job):)
The `1 suffix on "Nullable" is a normal encoding for generic type names, it indicates the generic type has one type argument. In other words, for Nullable<> you'll never see !1 being used.
所以简单地把!0
读作"T".或者使用更好的反编译器.