Type 和 TypeInfo 有什么区别或关系?
What's the difference or relationship between Type and TypeInfo?
我无法完全理解何时使用一个或另一个。他们是如此相似,以至于时不时地让我和他们感到困惑。说到反射,不知道是用plain Type还是TypeInfo
.NET Framework 本身增加了与 assembly.DefinedTypes
之类的混淆。它检索了一个 IEnumerable<TypeInfo>
,我认为它应该是 IEnumerable<Type>
。此外,还有一个 typeInfo.AsType()
方法。那是什么意思?它们可以互换吗?
而且他们的方法真的很相似
看来TypeInfo是经典的更强大的版本Type
。我错了吗?
来自MSDN docs:
A TypeInfo object represents the type definition itself, whereas a
Type object represents a reference to the type definition. Getting a
TypeInfo object forces the assembly that contains that type to load.
In comparison, you can manipulate Type objects without necessarily
requiring the runtime to load the assembly they reference.
因此 Type
提供了对象数据的更浅层表示,即将类型的名称提供为字符串。
其中 TypeInfo
提供了更丰富的类型表示,包括成员列表、实现的接口和基类型。
更详细地解释了差异 here。
我无法完全理解何时使用一个或另一个。他们是如此相似,以至于时不时地让我和他们感到困惑。说到反射,不知道是用plain Type还是TypeInfo
.NET Framework 本身增加了与 assembly.DefinedTypes
之类的混淆。它检索了一个 IEnumerable<TypeInfo>
,我认为它应该是 IEnumerable<Type>
。此外,还有一个 typeInfo.AsType()
方法。那是什么意思?它们可以互换吗?
而且他们的方法真的很相似
看来TypeInfo是经典的更强大的版本Type
。我错了吗?
来自MSDN docs:
A TypeInfo object represents the type definition itself, whereas a Type object represents a reference to the type definition. Getting a TypeInfo object forces the assembly that contains that type to load. In comparison, you can manipulate Type objects without necessarily requiring the runtime to load the assembly they reference.
因此 Type
提供了对象数据的更浅层表示,即将类型的名称提供为字符串。
其中 TypeInfo
提供了更丰富的类型表示,包括成员列表、实现的接口和基类型。
更详细地解释了差异 here。