Object.GetType()来源$ C ​​$ C来源、Object、GetType

2023-09-06 07:05:20 作者:醉酒绕人心

是如何的 object.GetType()的.NET中实现的?

How is object.GetType() implemented in .NET?

推荐答案

它在运行时本身实现的,所以没有C#源 - code吧。

It's implemented in the runtime itself, so there is no C# source-code for it.

[MethodImpl(MethodImplOptions.InternalCall)]
public extern Type GetType();

MethodImplOptions.InternalCall 用于其中有一个神奇的执行运行时本身内部的功能。

MethodImplOptions.InternalCall is used for functions which have a "magical" implementation inside the runtime itself.

对于正常的.NET实现你不会找到它,因为在所有的闭源。随着转子或单声道,你很可能会发现自己的C / C ++运行时源 - code。

For the normal .net implementation you won't find it at all since its closed source. With Rotor or Mono you'll most likely find in their c/c++ runtime source-code.

我认为它只是使用了标识指针在每个实例的开始去的类的信息,然后包含字段才能到管理键入例如,可能按需创建它。

I assume it just uses the marker pointer at the beginning of each instance to get to the class information which then contains a field to get to the managed Type instance, possibly creating it on demand.

 
精彩推荐