为什么!0是Microsoft中间语言(MSIL)的类型? [英] Why is !0 a type in Microsoft Intermediate Language (MSIL)?

查看:75
本文介绍了为什么!0是Microsoft中间语言(MSIL)的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在许多MSIL列表中,我观察到以下内容:

In many MSIL listings, I have observed the following:

System.Nullable`1<!0> etc ...

class !0 etc ...

<$是什么意思c $ c>!0 在这种情况下?

推荐答案

这是您使用的反编译器的怪癖查看.NET程序集。这是ildasm.exe的行为,其他诸如Reflector或ILSpy的行为都可以解决此问题。编写它的Microsoft程序员采用了一条捷径,他从IL生成一个字符串,该字符串仅以编码方式显示类型实参,而无需编写 extra 代码在元数据中查找类型实参名称。

This is quirk of the decompiler you use to look at a .NET assembly. It is the behavior of ildasm.exe, other ones like Reflector or ILSpy get this right. The Microsoft programmer who wrote it took a shortcut, he generates a string from the IL that just displays the type argument the way it is encoded, without writing the extra code to lookup the type argument name in the metadata.

您需要阅读!n 作为泛型类型的第n个类型参数。其中!0表示第一类型参数,!1表示第二类型参数,等等。对于Nullable<>,您从MSDN文章中知道'!0'表示'T'。

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 。两个感叹号指示通用方法的类型自变量。这次,ildasm.exe 确实查找类型参数名称,而不是使用 !! 0 。为什么程序员在通用类型上选择捷径而不在通用方法上采用捷径很难逆向工程。 Ildasm是一个非常古怪的程序,以C ++编码风格编写,与.NET中的其他C ++代码有很大不同。不像这是实习生的任务那样有纪律性,非零几率:)

You may also encounter something like !!T. Two exclamation marks indicate a type argument for a generic method. This time, ildasm.exe does look up the type argument name instead of using !!0. Why the programmer took the shortcut on generic types but not on generic methods is hard to reverse-engineer. Ildasm is a pretty quirky program and is written in a C++ coding style that's very different from other C++ code in .NET. Not as disciplined, non-zero odds that this was an intern's assignment :)

Nullable上的后缀1是通用类型名称的常规编码,它指示泛型类型具有一个类型参数。换句话说,对于Nullable<>,您永远不会看到使用了!1。

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。或使用更好的反编译器。

So simply read !0 as "T". Or use a better decompiler.

这篇关于为什么!0是Microsoft中间语言(MSIL)的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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