Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何';类型';工作_C#_Types - Fatal编程技术网

C# 如何';类型';工作

C# 如何';类型';工作,c#,types,C#,Types,我很好奇C#中typeof的“方法体”是什么样子(我很确定我无法在reflector中找到它,因为它是一个关键字而不是一个方法) 我猜它相当于GetType(将符号神奇地转换为字符串) 查看Reflector中的GetType(string),它调用一个方法“PrivateGetType”,该方法调用“RuntimeTypeHandle.GetTypeByName”,RuntimeTypeHandle中似乎有很多类型背后的逻辑,但是GetTypeByName的内容不会出现在Reflector中。

我很好奇C#中typeof的“方法体”是什么样子(我很确定我无法在reflector中找到它,因为它是一个关键字而不是一个方法)

我猜它相当于GetType(将符号神奇地转换为字符串)


查看Reflector中的GetType(string),它调用一个方法“PrivateGetType”,该方法调用“RuntimeTypeHandle.GetTypeByName”,RuntimeTypeHandle中似乎有很多类型背后的逻辑,但是GetTypeByName的内容不会出现在Reflector中。

如果您执行以下操作:

Type t = typeof(string);
然后编译器将
typeof(string)
位编译为MSIL指令,然后调用以获取
Type
类的实例


Type.GetTypeFromHandle
由运行时实现(这就是为什么它被标记为“MethodImplOptions.InternalCall”属性)。您可以查看mono的源代码,了解它是如何实际实现的,但您基本上必须了解整个元数据系统,才能了解
Type
和friends是如何在内部工作的…

谢谢这一点。正如你所说的GetTypeFromHandle也是extern,但我一直在考虑在mono上寻找这类东西,所以花时间投资可能是值得的。