[英]What's the difference between type definition and type reference?
I am reading the book CLR via C#
by Jeffrey Richter
. 我正在阅读
Jeffrey Richter
CLR via C#
书。
In Chapter 23(23.3.2)
, it says "A System.Type object represents a type reference(as opposed to a type definition)."
在
Chapter 23(23.3.2)
,它说"A System.Type object represents a type reference(as opposed to a type definition)."
What do the type reference and type definition mean here? 类型引用和类型定义在这里意味着什么?
The author is contrasting System.Type
with System.TypeInfo
. 作者将
System.Type
与System.TypeInfo
对比。 From the documentation : 从文档中 :
A TypeInfo object represents the type definition itself , whereas a Type object represents a reference to the type definition .
TypeInfo对象表示类型定义本身 ,而Type对象表示对类型定义的引用 。
The System.TypeInfo
for a class can only be instantiated if the assembly that implements the class (the type definition) is loaded or loadable. 仅当实现类的程序集(类型定义)已加载或可加载时,才能实例化类的
System.TypeInfo
。 To instantiate a System.Type
, the only requirement is that the current program contains a reference to the implementing assembly. 要实例化
System.Type
,唯一的要求是当前程序包含对实现程序集的引用 。
See also What's the difference between Type and TypeInfo? 另请参阅Type和TypeInfo有什么区别?
A type definition happens when you define a new type through a class, a struct, an interface or an enum. 当您通过类,结构,接口或枚举定义新类型时,就会发生类型定义。
A type reference is a collection of information about a type, eg its name or its members. 类型引用是有关类型的信息的集合,例如类型名称或成员。
The System.Type
class is able to represent a type, but not define a type. System.Type
类能够表示类型,但不能定义类型。 When you call typeof(TypeName)
or object.GetType()
, you will deal with representations of types with objects of System.Type
. 当调用
typeof(TypeName)
或object.GetType()
,将使用System.Type
对象处理类型的表示形式。
You can not directly instantiate an object of a type by just using a System.Type
object. 您不能仅使用
System.Type
对象直接实例化类型的对象。 It only describes the type, but not is the type. 它只是描述的类型,但不能是类型。 That's why it is called a reference.
这就是为什么它被称为参考。
A type definition implies the actual implementation of the type, such as, for example if it is a class, it means the definition of the class (with all its properties and fields). 类型定义表示类型的实际实现,例如,如果它是一个类,则表示该类的定义(及其所有属性和字段)。
A type reference , simply means that System.Type
contains the details of a particular type, that is, it is the meta-data about the Type. 类型引用 ,仅表示
System.Type
包含特定类型的详细信息,即它是有关Type的元数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.