Represents type declarations: class types, interface types, array types, value types, enumeration types, type parameters, generic type definitions, and open or closed constructed generic types.
See Also: Type Members
Type is the root of the System.Reflection functionality and is the primary way to access metadata. Use the members of Type to get information about a type declaration, such as the constructors, methods, fields, properties, and events of a class, as well as the module and the assembly in which the class is deployed.
The C# typeof operator (GetType operator in Visual Basic, typeid operator in Visual C++) returns a Type object.
A Type object that represents a type is unique; that is, two Type object references refer to the same object if and only if they represent the same type. This allows for comparison of Type objects using reference equality.
No permissions are required for code to use reflection to get information about types and their members, regardless of their access levels. No permissions are required for code to use reflection to access public members, or other members whose access levels would make them visible during normal compilation. However, in order for your code to use reflection to access members that would normally be inaccessible, such as private or internal methods, or protected fields of a type your class does not inherit, your code must have System.Security.Permissions.ReflectionPermission. See Security Considerations for Reflection.
Type is an abstract base class that allows multiple implementations. The system will always provide the derived class RuntimeType. In reflection, all classes beginning with the word Runtime are created only once per object in the system and support comparison operations.
In multithreading scenarios, do not lock Type objects in order to synchronize access to static data. Other code, over which you have no control, might also lock your class type. This might result in a deadlock. Instead, synchronize access to static data by locking a private static object.
This class is thread safe; multiple threads can concurrently read from an instance of this type. An instance of Type can represent any of the following types:
Classes
Value types
Arrays
Interfaces
Pointers
Enumerations
Constructed generic types and generic type definitions
Type arguments and type parameters of constructed generic types, generic type definitions, and generic method definitions
A reference to the Type object associated with a type can be obtained in the following ways:
The object.GetType method returns a Type object that represents the type of an instance.
The static GetType methods return a Type object that represents a type specified by its fully qualified name.
The System.Reflection.Module.GetTypes, System.Reflection.Module.GetType(string, bool), and System.Reflection.Module.FindTypes(System.Reflection.TypeFilter, object) methods return Type objects that represent the types defined in a module. The first method can be used to obtain an array of Type objects for all the public and private types defined in a module. (You can obtain an instance of Module through the System.Reflection.Assembly.GetModule(string) or System.Reflection.Assembly.GetModules method, or through the Type.Module property.)
The System.Reflection.Assembly object contains a number of methods to retrieve the classes defined in an assembly, including erload:System.Reflection.Assembly.GetType, System.Reflection.Assembly.GetTypes, and System.Reflection.Assembly.GetExportedTypes.
The Type.FindInterfaces(System.Reflection.TypeFilter, object) method returns a filtered list of interface types supported by a type.
The Type.GetElementType method returns a Type object that represents the element.
The Type.GetInterfaces and Type.GetInterface(string) methods return Type objects representing the interface types supported by a type.
The Type.GetTypeArray(Object[]) method returns an array of Type objects representing the types specified by an arbitrary set of objects. The objects are specified with an array of type Object.
The Type.GetTypeFromProgID(string) and Type.GetTypeFromCLSID(Guid) methods are provided for COM interoperability. They return a Type object that represents the type specified by a ProgID or CLSID.
The Type.GetTypeFromHandle(RuntimeTypeHandle) method is provided for interoperability. It returns a Type object that represents the type specified by a class handle.
The C# typeof operator, the C++ typeid operator, and the Visual Basic GetType operator obtain the Type object for a type.
The Type.MakeGenericType(Type[]) method returns a Type object representing a constructed generic type, which is an open constructed type if its Type.ContainsGenericParameters property returns true, and a closed constructed type otherwise. A generic type can be instantiated only if it is closed.
The erload:System.Type.MakeArrayType, Type.MakePointerType, and Type.MakeByRefType methods return Type objects that represent, respectively, an array of a specified type, a pointer to a specified type, and the type of a reference parameter (ref in C#, ByRef in Visual Basic).
A derived class can access protected members of the calling code's base classes. Also, access is allowed to assembly members of the calling code's assembly. As a rule, if you are allowed access in early-bound code, then you are also allowed access in late-bound code.
Interfaces that extend other interfaces do not inherit the methods defined in the extended interfaces.