When does the UnderlyingSystemType differ from the current Type instance

怎甘沉沦 提交于 2020-01-01 01:17:15

问题


System.Type contains an UnderlyingSystemType property. MSDN states that it:

Indicates the type provided by the common language runtime that represents this type.

In most cases, this property simply returns the current Type instance.

My question is, in what circumstances does this property not return the current Type instance itself. And in those cases, what sort of type will be the current Type instance and the returned underlying system type be?


回答1:


To be honest I never did it by myself, but I know that it is possible to create your own RuntimeType like definition of your specified type.

If you notice the Type class is abstract and has a lot of abstract memebers. What happens is that your type (whatever is it) automatically creates RuntimeType derived from Type class and implements it for your type.

So the property UnderlyingSystemType in case of orindary RuntimeType will return Type property equal value, in case of overriden implementation, instead, (that is for influencing relfection behavior, but I repeat I personally never did this before), will return user-defined type value.

EDIT

Actually the link provided by guys in comments is a good one:

When is a Type not a Type?



来源:https://stackoverflow.com/questions/11227136/when-does-the-underlyingsystemtype-differ-from-the-current-type-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!