Collapse AllExpand All      Code: All Code: Multiple Code: Visual Basic Code: C# Code: Visual C++ Code: F# Code: JScript 
Type Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)
<SerializableAttribute> _
Public MustInherit Class Type _
	Inherits MemberInfo _
	Implements IReflect
[SerializableAttribute]
public abstract class Type : MemberInfo, 
	IReflect
[SerializableAttribute]
public ref class Type abstract : public MemberInfo, 
	IReflect
[<AbstractClass>]
[<SerializableAttribute>]
type Type =  
    class
        inherit MemberInfo
        interface IReflect
    end
public abstract class Type extends MemberInfo implements IReflect

The Type type exposes the following members.

  NameDescription
Protected method TypeInitializes a new instance of the Type class.
Top
  NameDescription
Public property AssemblyGets the Assembly in which the type is declared. For generic types, gets the Assembly in which the generic type is defined.
Public property AssemblyQualifiedNameGets the assembly-qualified name of the Type, which includes the name of the assembly from which the Type was loaded.
Public property BaseTypeGets the type from which the current Type directly inherits.
Public property DeclaringTypeGets the type that declares the current nested type or generic type parameter. (Overrides MemberInfo..::..DeclaringType.)
Public property FullNameGets the fully qualified name of the Type, including the namespace of the Type but not the assembly.
Public property IsAbstractGets a value indicating whether the Type is abstract and must be overridden.
Public property IsArrayGets a value indicating whether the Type is an array.
Public property IsClassGets a value indicating whether the Type is a class; that is, not a value type or interface.
Public property IsEnumGets a value indicating whether the current Type represents an enumeration.
Public property IsInterfaceGets a value indicating whether the Type is an interface; that is, not a class or a value type.
Public property IsNotPublicGets a value indicating whether the Type is not declared public.
Public property IsPublicGets a value indicating whether the Type is declared public.
Public property IsSerializableGets a value indicating whether the Type is serializable.
Public property IsValueTypeGets a value indicating whether the Type is a value type.
Public property MemberTypeWhen overridden in a derived class, gets a MemberTypes value indicating the type of the member — method, constructor, event, and so on. (Inherited from MemberInfo.)
Public property NameGets the name of the current member. (Inherited from MemberInfo.)
Top
  NameDescription
Public method Equals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetConstructorSearches for a public instance constructor whose parameters match the types in the specified array.
Public method GetElementTypeWhen overridden in a derived class, returns the Type of the object encompassed or referred to by the current array, pointer or reference type.
Public method GetField(String)Searches for the public field with the specified name.
Public method GetField(String, BindingFlags)Searches for the specified field, using the specified binding constraints.
Public method GetFields()()()()Returns all the public fields of the current Type.
Public method GetFields(BindingFlags)When overridden in a derived class, searches for the fields defined for the current Type, using the specified binding constraints.
Public method GetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public method GetInterfacesWhen overridden in a derived class, gets all the interfaces implemented or inherited by the current Type.
Public method GetMethod(String)Searches for the public method with the specified name.
Public method GetMethod(String, BindingFlags)Searches for the specified method, using the specified binding constraints.
Public method GetMethod(String, array<Type>[]()[][])Searches for the specified public method whose parameters match the specified argument types.
Public method GetMethods()()()()Returns all the public methods of the current Type.
Public method GetMethods(BindingFlags)When overridden in a derived class, searches for the methods defined for the current Type, using the specified binding constraints.
Public method GetType()()()()Gets the Type of the current instance. (Inherited from Object.)
Public method Static member GetType(String)Gets the Type with the specified name, performing a case-sensitive search.
Public method Static member GetTypeFromHandleGets the type referenced by the specified type handle.
Public method InvokeMemberInvokes the specified member, using the specified binding constraints and matching the specified argument list.
Public method IsInstanceOfTypeDetermines whether the specified object is an instance of the current Type.
Public method IsSubclassOfDetermines whether the class represented by the current Type derives from the class represented by the specified Type.
Protected method MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public method ToStringReturns a String representing the name of the current Type. (Overrides Object..::..ToString()()()().)
Top

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.

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 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.

NoteNote

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 Module.GetTypes, Module.GetType, and Module.FindTypes 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 Assembly.GetModule or 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 Assembly..::..GetType, Assembly..::..GetTypes, and Assembly.GetExportedTypes.

  • The FindInterfaces method returns a filtered list of interface types supported by a type.

  • The GetElementType method returns a Type object that represents the element.

  • The GetInterfaces and GetInterface methods return Type objects representing the interface types supported by a type.

  • The GetTypeArray 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 GetTypeFromProgID and GetTypeFromCLSID methods are provided for COM interoperability. They return a Type object that represents the type specified by a ProgID or CLSID.

  • The GetTypeFromHandle 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 MakeGenericType method returns a Type object representing a constructed generic type, which is an open constructed type if its ContainsGenericParameters property returns true, and a closed constructed type otherwise. A generic type can be instantiated only if it is closed.

  • The MakeArrayType, MakePointerType, and 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).

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.