Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

The Type Class Is Just Another Type

A program manipulates or processes data of various types. For example, a program may add two integers to produce an integer result, or it may perform various string operations on a String type object. In all cases, you simply perform the appropriate operations on specific data types. The key to understanding reflection is that you are really doing the same thing, but you are performing especially interesting operations on an especially interesting type of data. In the previous sentence, you could substitute interesting with weird or puzzling. What makes it all a bit strange is that reflection involves operations on a data type that itself represents data type information. Douglas Hofstadter would call this a "strange loop." (See his book Go[um]del, Escher, Bach: An Eternal Golden Braid.)

Although it does seem a bit odd at first glance, the Type class really is just another type. Whereas the double data type represents an IEEE 64-bit floating-point value and the String class encapsulates a Unicode text string, the Type class encapsulates type information. An instance of the Type class encapsulates information about any arbitrary data type that you choose.

Every type has a range of possible values and a set of supported operators. For comparison, consider double and String types. A double type (which is a value type) may contain any value taken from a valid range of values; a set of operations are defined on the double type, such as addition, multiplication, and so forth. The String class pointer type (which is a reference type in .NET terminology, even though it is not a reference type in the C++ sense) may point to a valid String object on the heap, or it may be a null pointer. The String class also defines a set of operations that are defined by methods supported by the String class. The Type class pointer simply represents another data type with a set of supported operations. A variable of type Type may refer to (that is, point to) an instance of the Type class that encapsulates information about any arbitrary type.

  • + Share This
  • 🔖 Save To Your Account