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.

Inheritance Hierarchy

System. . :: . .Object
  System.Reflection. . :: . .MemberInfo
    System..::..Type

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

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

Constructors

  Name Description
Protected method Type Initializes a new instance of the Type class.

Top

Properties

  Name Description
Public property Assembly Gets the Assembly in which the type is declared. For generic types, gets the Assembly in which the generic type is defined.
Public property AssemblyQualifiedName Gets the assembly-qualified name of the Type, which includes the name of the assembly from which the Type was loaded.
Public property BaseType Gets the type from which the current Type directly inherits.
Public property DeclaringType Gets the type that declares the current nested type or generic type parameter. (Overrides MemberInfo. . :: . .DeclaringType.)
Public property FullName Gets the fully qualified name of the Type, including the namespace of the Type but not the assembly.
Public property IsAbstract Gets a value indicating whether the Type is abstract and must be overridden.
Public property IsArray Gets a value indicating whether the Type is an array.
Public property IsClass Gets a value indicating whether the Type is a class; that is, not a value type or interface.
Public property IsEnum Gets a value indicating whether the current Type represents an enumeration.
Public property IsInterface Gets a value indicating whether the Type is an interface; that is, not a class or a value type.
Public property IsNotPublic Gets a value indicating whether the Type is not declared public.
Public property IsPublic Gets a value indicating whether the Type is declared public.
Public property IsSerializable Gets a value indicating whether the Type is serializable.
Public property IsValueType Gets a value indicating whether the Type is a value type.
Public property MemberType When 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 Name Gets the name of the current member. (Inherited from MemberInfo.)

Top

Methods

  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetConstructor Searches for a public instance constructor whose parameters match the types in the specified array.
Public method GetElementType When 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 GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetInterfaces When 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 methodStatic member GetType(String) Gets the Type with the specified name, performing a case-sensitive search.
Public methodStatic member GetTypeFromHandle Gets the type referenced by the specified type handle.
Public method InvokeMember Invokes the specified member, using the specified binding constraints and matching the specified argument list.
Public method IsInstanceOfType Determines whether the specified object is an instance of the current Type.
Public method IsSubclassOf Determines whether the class represented by the current Type derives from the class represented by the specified Type.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a String representing the name of the current Type. (Overrides Object. . :: . .ToString() () () ().)

Top

Remarks

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.

Note

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

Thread Safety

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

See Also

Reference

System Namespace