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)

[<AbstractClass>]
[<SerializableAttribute>]
type Type =  
    class
        inherit MemberInfo
        interface IReflect
    end

The Type type exposes the following members.

  NameDescription
Protected methodTypeInitializes a new instance of the Type class.
Top

  NameDescription
Public propertyAssemblyGets the Assembly in which the type is declared. For generic types, gets the Assembly in which the generic type is defined.
Public propertyAssemblyQualifiedNameGets the assembly-qualified name of the Type, which includes the name of the assembly from which the Type was loaded.
Public propertyBaseTypeGets the type from which the current Type directly inherits.
Public propertyDeclaringTypeGets the type that declares the current nested type or generic type parameter. (Overrides MemberInfo..::..DeclaringType.)
Public propertyFullNameGets the fully qualified name of the Type, including the namespace of the Type but not the assembly.
Public propertyIsAbstractGets a value indicating whether the Type is abstract and must be overridden.
Public propertyIsArrayGets a value indicating whether the Type is an array.
Public propertyIsClassGets a value indicating whether the Type is a class; that is, not a value type or interface.
Public propertyIsEnumGets a value indicating whether the current Type represents an enumeration.
Public propertyIsInterfaceGets a value indicating whether the Type is an interface; that is, not a class or a value type.
Public propertyIsNotPublicGets a value indicating whether the Type is not declared public.
Public propertyIsPublicGets a value indicating whether the Type is declared public.
Public propertyIsSerializableGets a value indicating whether the Type is serializable.
Public propertyIsValueTypeGets a value indicating whether the Type is a value type.
Public propertyMemberTypeWhen 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 propertyNameGets the name of the current member. (Inherited from MemberInfo.)
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetConstructorSearches for a public instance constructor whose parameters match the types in the specified array.
Public methodGetElementTypeWhen overridden in a derived class, returns the Type of the object encompassed or referred to by the current array, pointer or reference type.
Public methodGetField(String)Searches for the public field with the specified name.
Public methodGetField(String, BindingFlags)Searches for the specified field, using the specified binding constraints.
Public methodGetFields()()()()Returns all the public fields of the current Type.
Public methodGetFields(BindingFlags)When overridden in a derived class, searches for the fields defined for the current Type, using the specified binding constraints.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetInterfacesWhen overridden in a derived class, gets all the interfaces implemented or inherited by the current Type.
Public methodGetMethod(String)Searches for the public method with the specified name.
Public methodGetMethod(String, BindingFlags)Searches for the specified method, using the specified binding constraints.
Public methodGetMethod(String, array<Type>[]()[][])Searches for the specified public method whose parameters match the specified argument types.
Public methodGetMethods()()()()Returns all the public methods of the current Type.
Public methodGetMethods(BindingFlags)When overridden in a derived class, searches for the methods defined for the current Type, using the specified binding constraints.
Public methodGetType()()()()Gets the Type of the current instance. (Inherited from Object.)
Public methodStatic memberGetType(String)Gets the Type with the specified name, performing a case-sensitive search.
Public methodStatic memberGetTypeFromHandleGets the type referenced by the specified type handle.
Public methodInvokeMemberInvokes the specified member, using the specified binding constraints and matching the specified argument list.
Public methodIsInstanceOfTypeDetermines whether the specified object is an instance of the current Type.
Public methodIsSubclassOfDetermines whether the class represented by the current Type derives from the class represented by the specified Type.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns 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.
Show: