What does self-descriptive type mean in .Net?

Given this MSDN article, we find out that the Common Type system in .NET has this classification of reference types:

"Link types can be types of self-describing types , pointer types , or . The type of the reference type can be determined by the values โ€‹โ€‹of self-describing types. Self-describing types are further divided into arrays and class types . "

  • So, an array, for example, is a self-descriptive type, because we can determine its type from its values?
  • How?
  • Is that what, or is there more for this definition?
+7
types
source share
3 answers

A self-describing type is a type that is described by metadata that is available about itself. The most common form is class types. It is quite easy to show there that self-description means:

The type itself is described by the class definition. e.g. Client class with name, age, and client. The pure data for an instance of this class will be something like this:

8%3|*1C USTOMER 

Just because there is a class description in the environment that contains metadata that you really know that some of this data forms an identifier, age, and name. And to identify metadata, the content content of the object is combined with the class identifier, so the environment can match the class description with metadata.

 |Class metadata reference: Metadata for the customer class | |Customer ID: Field | | |Customer Age: Field | | ||Customer Name : Field 8%3|*1C USTOMER 

For arrays, this is similar: array classes contain information about the number of records, as well as type information (see above) about stored records.

+3
source share

A self-describing type is a data type that provides information about itself in the interests of the garbage collector. Basically, any type that has some form of metadata, for example. assembly will be considered a self-describing type.

+3
source share

Perhaps the best way to show how pointer types and interface types are not described independently, for example:

 using System; interface ISample { } class CSample : ISample { } class Program { static unsafe void Main(string[] args) { ISample itf = new CSample(); var it = itf.GetType(); Console.WriteLine(it.FullName); int value = 42; int* p = &value; var pt = p->GetType(); Console.WriteLine(pt.FullName); Console.ReadLine(); } } 

Output:

 CSample System.Int32 

In other words, objects declared as an interface type can only describe a class that implements them. Pointers can only describe the type of object they are pointing to.

+3
source share

All Articles