Type Class

July 28, 2014

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)

'Declaration
Public MustInherit Class Type _
	Inherits MemberInfo _
	Implements IReflect

The Type type exposes the following members.

  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 propertyAttributesGets the attributes associated with the Type.
Public propertyBaseTypeGets the type from which the current Type directly inherits.
Public propertyContainsGenericParametersGets a value indicating whether the current Type object has type parameters that have not been replaced by specific types.
Public propertyCustomAttributesGets a collection that contains this member's custom attributes. (Inherited from MemberInfo.)
Public propertyDeclaringMethodGets a MethodBase that represents the declaring method, if the current Type represents a type parameter of a generic method.
Public propertyDeclaringTypeGets the type that declares the current nested type or generic type parameter. (Overrides MemberInfo.DeclaringType.)
Public propertyStatic memberDefaultBinderGets a reference to the default binder, which implements internal rules for selecting the appropriate members to be called by InvokeMember.
Public propertyFullNameGets the fully qualified name of the Type, including the namespace of the Type but not the assembly.
Public propertyGenericParameterAttributesGets a combination of GenericParameterAttributes flags that describe the covariance and special constraints of the current generic type parameter.
Public propertyGenericParameterPositionGets the position of the type parameter in the type parameter list of the generic type or method that declared the parameter, when the Type object represents a type parameter of a generic type or a generic method.
Public propertyGenericTypeArgumentsGets an array of the generic type arguments for this type.
Public propertyGUIDGets the GUID associated with the Type.
Public propertyHasElementTypeGets a value indicating whether the current Type encompasses or refers to another type; that is, whether the current Type is an array, a pointer, or is passed by reference.
Public propertyIsAbstractGets a value indicating whether the Type is abstract and must be overridden.
Public propertyIsAnsiClassGets a value indicating whether the string format attribute AnsiClass is selected for the Type.
Public propertyIsArrayGets a value indicating whether the Type is an array.
Public propertyIsAutoClassGets a value indicating whether the string format attribute AutoClass is selected for the Type.
Public propertyIsAutoLayoutGets a value indicating whether the class layout attribute AutoLayout is selected for the Type.
Public propertyIsByRefGets a value indicating whether the Type is passed by reference.
Public propertyIsClassGets a value indicating whether the Type is a class; that is, not a value type or interface.
Public propertyIsCOMObjectGets a value indicating whether the Type is a COM object.
Public propertyIsConstructedGenericTypeGets a value that indicates whether this object represents a constructed generic type.
Public propertyIsEnumGets a value indicating whether the current Type represents an enumeration.
Public propertyIsExplicitLayoutGets a value indicating whether the class layout attribute ExplicitLayout is selected for the Type.
Public propertyIsGenericParameterGets a value indicating whether the current Type represents a type parameter in the definition of a generic type or method.
Public propertyIsGenericTypeGets a value indicating whether the current type is a generic type.
Public propertyIsGenericTypeDefinitionGets a value indicating whether the current Type represents a generic type definition, from which other generic types can be constructed.
Public propertyIsImportGets a value indicating whether the Type has a ComImportAttribute attribute applied, indicating that it was imported from a COM type library.
Public propertyIsInterfaceGets a value indicating whether the Type is an interface; that is, not a class or a value type.
Public propertyIsLayoutSequentialGets a value indicating whether the class layout attribute SequentialLayout is selected for the Type.
Public propertyIsMarshalByRefGets a value indicating whether the Type is marshaled by reference.
Public propertyIsNestedGets a value indicating whether the current Type object represents a type whose definition is nested inside the definition of another type.
Public propertyIsNestedAssemblyGets a value indicating whether the Type is nested and visible only within its own assembly.
Public propertyIsNestedFamANDAssemGets a value indicating whether the Type is nested and visible only to classes that belong to both its own family and its own assembly.
Public propertyIsNestedFamilyGets a value indicating whether the Type is nested and visible only within its own family.
Public propertyIsNestedFamORAssemGets a value indicating whether the Type is nested and visible only to classes that belong to either its own family or to its own assembly.
Public propertyIsNestedPrivateGets a value indicating whether the Type is nested and declared private.
Public propertyIsNestedPublicGets a value indicating whether a class is nested and declared public.
Public propertyIsNotPublicGets a value indicating whether the Type is not declared public.
Public propertyIsPointerGets a value indicating whether the Type is a pointer.
Public propertyIsPrimitiveGets a value indicating whether the Type is one of the primitive types.
Public propertyIsPublicGets a value indicating whether the Type is declared public.
Public propertyIsSealedGets a value indicating whether the Type is declared sealed.
Public propertyIsSerializableGets a value indicating whether the Type is serializable.
Public propertyIsSpecialNameGets a value indicating whether the Type has a name that requires special handling.
Public propertyIsUnicodeClassGets a value indicating whether the string format attribute UnicodeClass is selected for the Type.
Public propertyIsValueTypeGets a value indicating whether the Type is a value type.
Public propertyIsVisibleGets a value indicating whether the Type can be accessed by code outside the assembly.
Public propertyMemberTypeGets a MemberTypes value indicating that this member is a type or a nested type. (Overrides MemberInfo.MemberType.)
Public propertyMetadataTokenGets a value that identifies a metadata element. (Inherited from MemberInfo.)
Public propertyModuleGets the module (the DLL) in which the current Type is defined.
Public propertyNameGets the name of the current member. (Inherited from MemberInfo.)
Public propertyNamespaceGets the namespace of the Type.
Public propertyReflectedTypeGets the class object that was used to obtain this member. (Overrides MemberInfo.ReflectedType.)
Public propertyTypeHandleGets the handle for the current Type.
Public propertyUnderlyingSystemTypeIndicates the type provided by the common language runtime that represents this type.
Top

  NameDescription
Public methodEquals(Object)Determines if the underlying system type of the current Type is the same as the underlying system type of the specified Object. (Overrides MemberInfo.Equals(Object).)
Public methodEquals(Type)Determines if the underlying system type of the current Type is the same as the underlying system type of the specified Type.
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodFindMembersReturns a filtered array of MemberInfo objects of the specified member type.
Public methodGetArrayRankGets the number of dimensions in an Array.
Protected methodGetAttributeFlagsImplWhen overridden in a derived class, implements the Attributes property and gets a bitmask indicating the attributes associated with the Type.
Public methodGetConstructor(Type())Searches for a public instance constructor whose parameters match the types in the specified array.
Public methodGetConstructor(BindingFlags, Binder, Type(), ParameterModifier())Searches for a constructor whose parameters match the specified argument types and modifiers, using the specified binding constraints.
Protected methodGetConstructorImplWhen overridden in a derived class, searches for a constructor whose parameters match the specified argument types and modifiers, using the specified binding constraints and the specified calling convention.
Public methodGetConstructorsReturns all the public constructors defined for the current Type.
Public methodGetConstructors(BindingFlags)When overridden in a derived class, searches for the constructors defined for the current Type, using the specified BindingFlags.
Public methodGetCustomAttributes(Boolean)When overridden in a derived class, returns an array of all custom attributes applied to this member. (Inherited from MemberInfo.)
Public methodGetCustomAttributes(Type, Boolean)When overridden in a derived class, returns an array of custom attributes applied to this member and identified by Type. (Inherited from MemberInfo.)
Public methodGetDefaultMembersSearches for the members defined for the current Type whose DefaultMemberAttribute is set.
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 methodGetEvent(String)Returns the EventInfo object representing the specified public event.
Public methodGetEvent(String, BindingFlags)When overridden in a derived class, returns the EventInfo object representing the specified event, using the specified binding constraints.
Public methodGetEventsReturns all the public events that are declared or inherited by the current Type.
Public methodGetEvents(BindingFlags)When overridden in a derived class, searches for events that are declared or inherited by the current Type, using the specified binding constraints.
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 methodGetFieldsReturns 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 methodGetGenericArgumentsReturns an array of Type objects that represent the type arguments of a generic type or the type parameters of a generic type definition.
Public methodGetGenericParameterConstraintsReturns an array of Type objects that represent the constraints on the current generic type parameter.
Public methodGetGenericTypeDefinitionReturns a Type object that represents a generic type definition from which the current generic type can be constructed.
Public methodGetHashCodeReturns the hash code for this instance. (Overrides MemberInfo.GetHashCode.)
Public methodGetInterfaceWhen overridden in a derived class, searches for the specified interface, specifying whether to do a case-insensitive search for the interface name.
Public methodGetInterfaceMapReturns an interface mapping for the specified interface type.
Public methodGetInterfacesWhen overridden in a derived class, gets all the interfaces implemented or inherited by the current Type.
Public methodGetMember(String)Searches for the public members with the specified name.
Public methodGetMember(String, BindingFlags)Searches for the specified members, using the specified binding constraints.
Public methodGetMember(String, MemberTypes, BindingFlags)Searches for the specified members of the specified member type, using the specified binding constraints.
Public methodGetMembersReturns all the public members of the current Type.
Public methodGetMembers(BindingFlags)When overridden in a derived class, searches for the members defined for the current Type, using the specified binding constraints.
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, Type())Searches for the specified public method whose parameters match the specified argument types.
Public methodGetMethod(String, Type(), ParameterModifier())Searches for the specified public method whose parameters match the specified argument types and modifiers.
Public methodGetMethod(String, BindingFlags, Binder, Type(), ParameterModifier())Searches for the specified method whose parameters match the specified argument types and modifiers, using the specified binding constraints.
Public methodGetMethod(String, BindingFlags, Binder, CallingConventions, Type(), ParameterModifier())Searches for the specified method whose parameters match the specified argument types and modifiers, using the specified binding constraints and the specified calling convention.
Protected methodGetMethodImplWhen overridden in a derived class, searches for the specified method whose parameters match the specified argument types and modifiers, using the specified binding constraints and the specified calling convention.
Public methodGetMethodsReturns 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 methodGetNestedTypeWhen overridden in a derived class, searches for the specified nested type, using the specified binding constraints.
Public methodGetNestedTypesWhen overridden in a derived class, searches for the types nested in the current Type, using the specified binding constraints.
Public methodGetPropertiesReturns all the public properties of the current Type.
Public methodGetProperties(BindingFlags)When overridden in a derived class, searches for the properties of the current Type, using the specified binding constraints.
Public methodGetProperty(String)Searches for the public property with the specified name.
Public methodGetProperty(String, BindingFlags)Searches for the specified property, using the specified binding constraints.
Public methodGetProperty(String, Type)Searches for the public property with the specified name and return type.
Public methodGetProperty(String, Type, Type())Searches for the specified public property whose parameters match the specified argument types.
Public methodGetProperty(String, Type, Type(), ParameterModifier())Searches for the specified public property whose parameters match the specified argument types and modifiers.
Public methodGetProperty(String, BindingFlags, Binder, Type, Type(), ParameterModifier())Searches for the specified property whose parameters match the specified argument types and modifiers, using the specified binding constraints.
Protected methodGetPropertyImplWhen overridden in a derived class, searches for the specified property whose parameters match the specified argument types and modifiers, using the specified binding constraints.
Public methodGetTypeGets the current Type.
Public methodStatic memberGetType(String)Gets the Type with the specified name, performing a case-sensitive search.
Public methodStatic memberGetType(String, Boolean)Gets the Type with the specified name, performing a case-sensitive search and specifying whether to throw an exception if the type is not found.
Public methodStatic memberGetType(String, Boolean, Boolean)Gets the Type with the specified name, specifying whether to perform a case-sensitive search and whether to throw an exception if the type is not found.
Public methodStatic memberGetTypeCodeGets the underlying type code of the specified Type.
Public methodStatic memberGetTypeFromHandleGets the type referenced by the specified type handle.
Public methodStatic memberGetTypeHandleGets the handle for the Type of a specified object.
Protected methodHasElementTypeImplWhen overridden in a derived class, implements the HasElementType property and determines whether the current Type encompasses or refers to another type; that is, whether the current Type is an array, a pointer, or is passed by reference.
Public methodInvokeMember(String, BindingFlags, Binder, Object, Object())Invokes the specified member, using the specified binding constraints and matching the specified argument list.
Public methodInvokeMember(String, BindingFlags, Binder, Object, Object(), ParameterModifier(), CultureInfo, String())When overridden in a derived class, invokes the specified member, using the specified binding constraints and matching the specified argument list, modifiers and culture.
Protected methodIsArrayImplWhen overridden in a derived class, implements the IsArray property and determines whether the Type is an array.
Public methodIsAssignableFromDetermines whether an instance of the current Type can be assigned from an instance of the specified Type.
Protected methodIsByRefImplWhen overridden in a derived class, implements the IsByRef property and determines whether the Type is passed by reference.
Protected methodIsCOMObjectImplWhen overridden in a derived class, implements the IsCOMObject property and determines whether the Type is a COM object.
Public methodIsDefinedWhen overridden in a derived class, indicates whether one or more attributes of the specified type or of its derived types is applied to this member. (Inherited from MemberInfo.)
Public methodIsInstanceOfTypeDetermines whether the specified object is an instance of the current Type.
Protected methodIsPointerImplWhen overridden in a derived class, implements the IsPointer property and determines whether the Type is a pointer.
Protected methodIsPrimitiveImplWhen overridden in a derived class, implements the IsPrimitive property and determines whether the Type is one of the primitive types.
Public methodIsSubclassOfDetermines whether the class represented by the current Type derives from the class represented by the specified Type.
Protected methodIsValueTypeImplImplements the IsValueType property and determines whether the Type is a value type; that is, not a class or an interface.
Public methodMakeArrayTypeReturns a Type object representing a one-dimensional array of the current type, with a lower bound of zero.
Public methodMakeArrayType(Int32)Returns a Type object representing an array of the current type, with the specified number of dimensions.
Public methodMakeByRefTypeReturns a Type object that represents the current type when passed as a ref parameter (ByRef parameter in Visual Basic).
Public methodMakeGenericTypeSubstitutes the elements of an array of types for the type parameters of the current generic type definition and returns a Type object representing the resulting constructed type.
Public methodMakePointerTypeReturns a Type object that represents a pointer to the current 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

  NameDescription
Public Extension MethodGetCustomAttribute(Type)Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified member. (Defined by CustomAttributeExtensions.)
Public Extension MethodGetCustomAttribute(Type, Boolean)Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified member, and optionally inspects the ancestors of that member. (Defined by CustomAttributeExtensions.)
Public Extension MethodGetCustomAttribute(Of T)Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified member. (Defined by CustomAttributeExtensions.)
Public Extension MethodGetCustomAttribute(Of T)(Boolean)Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified member, and optionally inspects the ancestors of that member. (Defined by CustomAttributeExtensions.)
Public Extension MethodGetCustomAttributesOverloaded. Retrieves a collection of custom attributes that are applied to a specified member. (Defined by CustomAttributeExtensions.)
Public Extension MethodGetCustomAttributes(Type)Overloaded. Retrieves a collection of custom attributes of a specified type that are applied to a specified member. (Defined by CustomAttributeExtensions.)
Public Extension MethodGetCustomAttributes(Of T)Overloaded. Retrieves a collection of custom attributes of a specified type that are applied to a specified member. (Defined by CustomAttributeExtensions.)
Public Extension MethodGetCustomAttributes(Of T)(Boolean)Overloaded. Retrieves a collection of custom attributes of a specified type that are applied to a specified member, and optionally inspects the ancestors of that member. (Defined by CustomAttributeExtensions.)
Public Extension MethodGetRuntimeEventRetrieves an object that represents the specified event. (Defined by RuntimeReflectionExtensions.)
Public Extension MethodGetRuntimeEventsRetrieves a collection that represents all the events defined on a specified type. (Defined by RuntimeReflectionExtensions.)
Public Extension MethodGetRuntimeFieldRetrieves an object that represents a specified field. (Defined by RuntimeReflectionExtensions.)
Public Extension MethodGetRuntimeFieldsRetrieves a collection that represents all the fields defined on a specified type. (Defined by RuntimeReflectionExtensions.)
Public Extension MethodGetRuntimeMethodRetrieves an object that represents a specified method. (Defined by RuntimeReflectionExtensions.)
Public Extension MethodGetRuntimeMethodsRetrieves a collection that represents all methods defined on a specified type. (Defined by RuntimeReflectionExtensions.)
Public Extension MethodGetRuntimePropertiesRetrieves a collection that represents all the properties defined on a specified type. (Defined by RuntimeReflectionExtensions.)
Public Extension MethodGetRuntimePropertyRetrieves an object that represents a specified property. (Defined by RuntimeReflectionExtensions.)
Public Extension MethodGetTypeInfoReturns the TypeInfo representation of the specified type. (Defined by IntrospectionExtensions.)
Public Extension MethodIsDefinedIndicates whether custom attributes of a specified type are applied to a specified member. (Defined by CustomAttributeExtensions.)
Top

  NameDescription
Public fieldStatic memberDelimiterSeparates names in the namespace of the Type. This field is read-only.
Public fieldStatic memberEmptyTypesRepresents an empty array of type Type. This field is read-only.
Public fieldStatic memberFilterNameIgnoreCaseRepresents the case-insensitive member filter used on names. This field is read-only.
Public fieldStatic memberMissingRepresents a missing value in the Type information. This field is read-only.
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.

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.

Type is an abstract base class. The system provides the internal (Friend in Visual Basic) derived class RuntimeType. In Windows Phone apps, you cannot derive from Type.

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 and Module.GetType 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 of the public and private types defined in a module. (You can obtain an instance of Module through the Assembly.GetModules method or through the Type.Module property.)

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

The following code example shows a few representative features of Type. The C# typeof operator (GetType operator in Visual Basic) is used to get a Type object representing String. From this Type object, the GetMethod method is used to get a MethodInfo representing the Substring overload that takes a starting location and a length.

To identify the overload signature, the code example creates a temporary array containing two Type objects representing int (Integer in Visual Basic).

NoteNote:

To be precise, the array contains two references to the instance of Type that represents int in the current application domain. For any type, there is only one instance of Type per application domain.

The code example uses the MethodInfo to invoke the Substring method on the string "Hello, World!", and displays the result.


Imports System.Reflection

Module Example

   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      Dim t As Type = GetType(String)

      Dim substr As MethodInfo = t.GetMethod("Substring", _
          New Type() {GetType(Integer), GetType(Integer)})

      Dim result As Object = _
          substr.Invoke("Hello, World!", New Object() {7, 5})
      outputBlock.Text += String.Format("{0} returned ""{1}"".", substr, result) & vbCrLf

   End Sub
End Module

' This code example produces the following output:
'
'System.String Substring(Int32, Int32) returned "World".


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

This type is thread safe.

Show:
© 2014 Microsoft