Export (0) Print
Expand All

Type Class

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)

[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
public abstract class Type : MemberInfo, 
	IReflect

The Type type exposes the following members.

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

  NameDescription
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360AssemblyGets the Assembly in which the type is declared. For generic types, gets the Assembly in which the generic type is defined.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360AssemblyQualifiedNameGets the assembly-qualified name of the Type, which includes the name of the assembly from which the Type was loaded.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360AttributesGets the attributes associated with the Type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360BaseTypeGets the type from which the current Type directly inherits.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360ContainsGenericParametersGets a value indicating whether the current Type object has type parameters that have not been replaced by specific types.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360DeclaringMethodGets a MethodBase that represents the declaring method, if the current Type represents a type parameter of a generic method.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360DeclaringTypeGets the type that declares the current nested type or generic type parameter. (Overrides MemberInfo.DeclaringType.)
Public propertyStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360DefaultBinderGets a reference to the default binder, which implements internal rules for selecting the appropriate members to be called by InvokeMember.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360FullNameGets the fully qualified name of the Type, including the namespace of the Type but not the assembly.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360GenericParameterAttributesGets a combination of GenericParameterAttributes flags that describe the covariance and special constraints of the current generic type parameter.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360GenericParameterPositionGets 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 propertySupported by Silverlight for Windows PhoneSupported by Xbox 360GUIDGets the GUID associated with the Type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360HasElementTypeGets 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 propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsAbstractGets a value indicating whether the Type is abstract and must be overridden.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsAnsiClassGets a value indicating whether the string format attribute AnsiClass is selected for the Type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsArrayGets a value indicating whether the Type is an array.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsAutoClassGets a value indicating whether the string format attribute AutoClass is selected for the Type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsAutoLayoutGets a value indicating whether the class layout attribute AutoLayout is selected for the Type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsByRefGets a value indicating whether the Type is passed by reference.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsClassGets a value indicating whether the Type is a class; that is, not a value type or interface.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsCOMObjectGets a value indicating whether the Type is a COM object.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsEnumGets a value indicating whether the current Type represents an enumeration.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsGenericParameterGets a value indicating whether the current Type represents a type parameter in the definition of a generic type or method.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsGenericTypeGets a value indicating whether the current type is a generic type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsGenericTypeDefinitionGets a value indicating whether the current Type represents a generic type definition, from which other generic types can be constructed.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsImportGets a value indicating whether the Type has a ComImportAttribute attribute applied, indicating that it was imported from a COM type library.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsInterfaceGets a value indicating whether the Type is an interface; that is, not a class or a value type.
Public propertySupported by Silverlight for Windows PhoneIsNestedGets a value indicating whether the current Type object represents a type whose definition is nested inside the definition of another type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsNestedAssemblyGets a value indicating whether the Type is nested and visible only within its own assembly.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsNestedFamANDAssemGets 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 propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsNestedFamilyGets a value indicating whether the Type is nested and visible only within its own family.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsNestedFamORAssemGets 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 propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsNestedPrivateGets a value indicating whether the Type is nested and declared private.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsNestedPublicGets a value indicating whether a class is nested and declared public.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsNotPublicGets a value indicating whether the Type is not declared public.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsPointerGets a value indicating whether the Type is a pointer.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsPrimitiveGets a value indicating whether the Type is one of the primitive types.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsPublicGets a value indicating whether the Type is declared public.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsSealedGets a value indicating whether the Type is declared sealed.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsSpecialNameGets a value indicating whether the Type has a name that requires special handling.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsUnicodeClassGets a value indicating whether the string format attribute UnicodeClass is selected for the Type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsValueTypeGets a value indicating whether the Type is a value type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsVisibleGets a value indicating whether the Type can be accessed by code outside the assembly.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360MemberTypeGets a MemberTypes value indicating that this member is a type or a nested type. (Overrides MemberInfo.MemberType.)
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360MetadataTokenGets a value that identifies a metadata element. (Inherited from MemberInfo.)
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360ModuleGets the module (the DLL) in which the current Type is defined.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360NameGets the name of the current member. (Inherited from MemberInfo.)
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360NamespaceGets the namespace of the Type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360ReflectedTypeGets the class object that was used to obtain this member. (Overrides MemberInfo.ReflectedType.)
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360TypeHandleGets the handle for the current Type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360UnderlyingSystemTypeIndicates the type provided by the common language runtime that represents this type.
Top

  NameDescription
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Equals(Object)Determines if the underlying system type of the current Type is the same as the underlying system type of the specified Object. (Overrides Object.Equals(Object).)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Equals(Type)Determines if the underlying system type of the current Type is the same as the underlying system type of the specified Type.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360FinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360FindMembersReturns a filtered array of MemberInfo objects of the specified member type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetArrayRankGets the number of dimensions in an Array.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetAttributeFlagsImplWhen overridden in a derived class, implements the Attributes property and gets a bitmask indicating the attributes associated with the Type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetConstructor(Type[])Searches for a public instance constructor whose parameters match the types in the specified array.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetConstructor(BindingFlags, Binder, Type[], ParameterModifier[])Searches for a constructor whose parameters match the specified argument types and modifiers, using the specified binding constraints.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetConstructorImplWhen 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 methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetConstructors()Returns all the public constructors defined for the current Type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetConstructors(BindingFlags)When overridden in a derived class, searches for the constructors defined for the current Type, using the specified BindingFlags.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetCustomAttributes(Boolean)When overridden in a derived class, returns an array of all custom attributes applied to this member. (Inherited from MemberInfo.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetCustomAttributes(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 methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetDefaultMembersSearches for the members defined for the current Type whose DefaultMemberAttribute is set.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetElementTypeWhen overridden in a derived class, returns the Type of the object encompassed or referred to by the current array, pointer or reference type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetEvent(String)Returns the EventInfo object representing the specified public event.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetEvent(String, BindingFlags)When overridden in a derived class, returns the EventInfo object representing the specified event, using the specified binding constraints.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetEvents()Returns all the public events that are declared or inherited by the current Type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetEvents(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 methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetField(String)Searches for the public field with the specified name.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetField(String, BindingFlags)Searches for the specified field, using the specified binding constraints.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetFields()Returns all the public fields of the current Type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetFields(BindingFlags)When overridden in a derived class, searches for the fields defined for the current Type, using the specified binding constraints.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetGenericArgumentsReturns an array of Type objects that represent the type arguments of a generic type or the type parameters of a generic type definition.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetGenericParameterConstraintsReturns an array of Type objects that represent the constraints on the current generic type parameter.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetGenericTypeDefinitionReturns a Type object that represents a generic type definition from which the current generic type can be constructed.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetHashCodeReturns the hash code for this instance. (Overrides Object.GetHashCode().)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetInterfaceWhen overridden in a derived class, searches for the specified interface, specifying whether to do a case-insensitive search for the interface name.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetInterfaceMapReturns an interface mapping for the specified interface type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetInterfacesWhen overridden in a derived class, gets all the interfaces implemented or inherited by the current Type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetMember(String)Searches for the public members with the specified name.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetMember(String, BindingFlags)Searches for the specified members, using the specified binding constraints.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetMember(String, MemberTypes, BindingFlags)Searches for the specified members of the specified member type, using the specified binding constraints.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetMembers()Returns all the public members of the current Type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetMembers(BindingFlags)When overridden in a derived class, searches for the members defined for the current Type, using the specified binding constraints.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetMethod(String)Searches for the public method with the specified name.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetMethod(String, BindingFlags)Searches for the specified method, using the specified binding constraints.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetMethod(String, Type[])Searches for the specified public method whose parameters match the specified argument types.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetMethod(String, Type[], ParameterModifier[])Searches for the specified public method whose parameters match the specified argument types and modifiers.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetMethod(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 methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetMethod(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 methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetMethodImplWhen 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 methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetMethods()Returns all the public methods of the current Type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetMethods(BindingFlags)When overridden in a derived class, searches for the methods defined for the current Type, using the specified binding constraints.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetNestedTypeWhen overridden in a derived class, searches for the specified nested type, using the specified binding constraints.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetNestedTypesWhen overridden in a derived class, searches for the types nested in the current Type, using the specified binding constraints.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetProperties()Returns all the public properties of the current Type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetProperties(BindingFlags)When overridden in a derived class, searches for the properties of the current Type, using the specified binding constraints.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetProperty(String)Searches for the public property with the specified name.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetProperty(String, BindingFlags)Searches for the specified property, using the specified binding constraints.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetProperty(String, Type)Searches for the public property with the specified name and return type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetProperty(String, Type, Type[])Searches for the specified public property whose parameters match the specified argument types.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetProperty(String, Type, Type[], ParameterModifier[])Searches for the specified public property whose parameters match the specified argument types and modifiers.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetProperty(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 methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetPropertyImplWhen 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 methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetType()Gets the current Type.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetType(String)Gets the Type with the specified name, performing a case-sensitive search.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetType(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 memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetType(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 memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetTypeCodeGets the underlying type code of the specified Type.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetTypeFromHandleGets the type referenced by the specified type handle.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetTypeHandleGets the handle for the Type of a specified object.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360HasElementTypeImplWhen 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 methodSupported by Silverlight for Windows PhoneSupported by Xbox 360InvokeMember(String, BindingFlags, Binder, Object, Object[])Invokes the specified member, using the specified binding constraints and matching the specified argument list.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360InvokeMember(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 methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IsArrayImplWhen overridden in a derived class, implements the IsArray property and determines whether the Type is an array.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IsAssignableFromDetermines whether an instance of the current Type can be assigned from an instance of the specified Type.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IsByRefImplWhen overridden in a derived class, implements the IsByRef property and determines whether the Type is passed by reference.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IsCOMObjectImplWhen overridden in a derived class, implements the IsCOMObject property and determines whether the Type is a COM object.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IsDefinedWhen 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 methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IsInstanceOfTypeDetermines whether the specified object is an instance of the current Type.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IsPointerImplWhen overridden in a derived class, implements the IsPointer property and determines whether the Type is a pointer.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IsPrimitiveImplWhen overridden in a derived class, implements the IsPrimitive property and determines whether the Type is one of the primitive types.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IsSubclassOfDetermines whether the class represented by the current Type derives from the class represented by the specified Type.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IsValueTypeImplImplements the IsValueType property and determines whether the Type is a value type; that is, not a class or an interface.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360MakeArrayType()Returns a Type object representing a one-dimensional array of the current type, with a lower bound of zero.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360MakeArrayType(Int32)Returns a Type object representing an array of the current type, with the specified number of dimensions.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360MakeByRefTypeReturns a Type object that represents the current type when passed as a ref parameter (ByRef parameter in Visual Basic).
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360MakeGenericTypeSubstitutes 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 methodSupported by Silverlight for Windows PhoneSupported by Xbox 360MakePointerTypeReturns a Type object that represents a pointer to the current type.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360ToStringReturns a String representing the name of the current Type. (Overrides Object.ToString().)
Top

  NameDescription
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360DelimiterSeparates names in the namespace of the Type. This field is read-only.
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360EmptyTypesRepresents an empty array of type Type. This field is read-only.
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360FilterNameIgnoreCaseRepresents the case-insensitive member filter used on names. This field is read-only.
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360MissingRepresents 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 Silverlight-based applications, 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.


using System;
using System.Reflection;

class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      Type t = typeof(String);

      MethodInfo substr = t.GetMethod("Substring",
          new Type[] { typeof(int), typeof(int) });

      Object result =
          substr.Invoke("Hello, World!", new Object[] { 7, 5 });
      outputBlock.Text += String.Format("{0} returned \"{1}\".", substr, result) + "\n";
   }
}

/* This code example produces the following output:

System.String Substring(Int32, Int32) returned "World".
 */


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

This type is thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft