UnderlyingSystemType(Property)&之间有什么区别? GetType()? [英] What's the difference between UnderlyingSystemType(Property) & GetType() ?

查看:69
本文介绍了UnderlyingSystemType(Property)&之间有什么区别? GetType()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,它们具有相同的性能.

In my view,they have same performance.

推荐答案

底层实现可能会给出答案.然后,GetType()方法和UnderlyingSystemType 来自 mscorlib.dll程序集的系统名称空间的Type类. GetType()方法在Type类中具有一个实现,具有以下实现(基于从 ILDasm 工具中提取的IL代码)
Underlying implementation will probably give the answer. Let''s do it then, GetType() method and UnderlyingSystemType is from Type class from System namespace of the mscorlib.dll assembly. GetType() method has a implementation in the Type class with following implementation (based on the IL code extracted from ILDasm tools)
public static Type GetType(string typeName)
{
    StackCrawlMark lookForMyCaller = StackCrawlMark.LookForMyCaller;
    return RuntimeType.GetType(typeName, false, false, false, ref lookForMyCaller);
}


我们需要更深入地研究此方法,如果我们看一下RuntimeType类的GetType(.....)的实现,我们可以在幕后看到它返回了RuntimType本身,


we need to dive deeper into this method, if we look the implementation if the GetType(.....) of the RuntimeType class we can see behind the scene it is returning the RuntimType itself as,

internal static RuntimeType GetType(string typeName, bool throwOnError, bool ignoreCase, bool reflectionOnly, ref StackCrawlMark stackMark)
{
    return RuntimeTypeHandle.GetTypeByName(typeName, throwOnError, ignoreCase, reflectionOnly, ref stackMark, false);
}


和GetTypeByName方法


and the GetTypeByName method,

internal static RuntimeType GetTypeByName(string name, bool throwOnError, bool ignoreCase, bool reflectionOnly, ref StackCrawlMark stackMark, bool loadTypeFromPartialName)
{
    RuntimeType o = null;
    GetTypeByName(name, throwOnError, ignoreCase, reflectionOnly, JitHelpers.GetStackCrawlMarkHandle(ref stackMark), loadTypeFromPartialName, JitHelpers.GetObjectHandleOnStack<RuntimeType>(ref o));
    return o;
}


但是UnderlyingSystemType通过以下实现被标记为抽象属性,


but UnderlyingSystemType is marked as abstract property with the following implementation,

public abstract Type UnderlyingSystemType { get; }


此属性在RuntimeType类中具有一个实现,其中,


This property has a implementation in the RuntimeType class in which is,

public override Type UnderlyingSystemType
{
    get
    {
        return this;
    }
}


因此,两者都返回RuntimeType对象作为结果.希望它能显示GetType()UnderlyingSystemType 的内部:)


So the both return the RuntimeType object as result. Hope it shows the internal of the GetType() and UnderlyingSystemType :)


这篇关于UnderlyingSystemType(Property)&amp;之间有什么区别? GetType()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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