Sdílet prostřednictvím


Type Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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)

Syntax

'Declaration
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.None)> _
Public MustInherit Class Type _
    Inherits MemberInfo _
    Implements IReflect
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
public abstract class Type : MemberInfo, 
    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 propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Assembly Gets 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 360 AssemblyQualifiedName Gets 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 360 Attributes Gets the attributes associated with the Type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 BaseType Gets the type from which the current Type directly inherits.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 ContainsGenericParameters Gets 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 360 DeclaringMethod Gets 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 360 DeclaringType Gets 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 360 DefaultBinder Gets 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 360 FullName Gets 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 360 GenericParameterAttributes Gets 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 360 GenericParameterPosition Gets 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 360 GUID Gets the GUID associated with the Type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 HasElementType Gets 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 360 IsAbstract Gets a value indicating whether the Type is abstract and must be overridden.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsAnsiClass Gets a value indicating whether the string format attribute AnsiClass is selected for the Type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsArray Gets a value indicating whether the Type is an array.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsAutoClass Gets a value indicating whether the string format attribute AutoClass is selected for the Type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsAutoLayout Gets a value indicating whether the class layout attribute AutoLayout is selected for the Type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsByRef Gets a value indicating whether the Type is passed by reference.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsClass Gets 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 360 IsCOMObject Gets a value indicating whether the Type is a COM object.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsEnum Gets a value indicating whether the current Type represents an enumeration.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsGenericParameter Gets 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 360 IsGenericType Gets a value indicating whether the current type is a generic type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsGenericTypeDefinition Gets 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 360 IsImport Gets 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 360 IsInterface Gets a value indicating whether the Type is an interface; that is, not a class or a value type.
Public propertySupported by Silverlight for Windows Phone IsNested Gets 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 360 IsNestedAssembly Gets a value indicating whether the Type is nested and visible only within its own assembly.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsNestedFamANDAssem Gets 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 360 IsNestedFamily Gets a value indicating whether the Type is nested and visible only within its own family.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsNestedFamORAssem Gets 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 360 IsNestedPrivate Gets a value indicating whether the Type is nested and declared private.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsNestedPublic Gets a value indicating whether a class is nested and declared public.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsNotPublic Gets a value indicating whether the Type is not declared public.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsPointer Gets a value indicating whether the Type is a pointer.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsPrimitive Gets a value indicating whether the Type is one of the primitive types.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsPublic Gets a value indicating whether the Type is declared public.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsSealed Gets a value indicating whether the Type is declared sealed.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsSpecialName Gets a value indicating whether the Type has a name that requires special handling.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsUnicodeClass Gets a value indicating whether the string format attribute UnicodeClass is selected for the Type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsValueType Gets a value indicating whether the Type is a value type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsVisible Gets a value indicating whether the Type can be accessed by code outside the assembly.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 MemberType Gets 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 360 MetadataToken Gets a value that identifies a metadata element. (Inherited from MemberInfo.)
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Module Gets the module (the DLL) in which the current Type is defined.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Name Gets the name of the current member. (Inherited from MemberInfo.)
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Namespace Gets the namespace of the Type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 ReflectedType Gets the class object that was used to obtain this member. (Overrides MemberInfo.ReflectedType.)
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 TypeHandle Gets the handle for the current Type.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 UnderlyingSystemType Indicates the type provided by the common language runtime that represents this type.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Equals(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 360 Equals(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 360 Finalize Allows 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 360 FindMembers Returns a filtered array of MemberInfo objects of the specified member type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetArrayRank Gets the number of dimensions in an Array.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetAttributeFlagsImpl When 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 360 GetConstructor(array<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 360 GetConstructor(BindingFlags, Binder, array<Type[], array<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 360 GetConstructorImpl When 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 360 GetConstructors() Returns all the public constructors defined for the current Type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetConstructors(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 360 GetCustomAttributes(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 360 GetCustomAttributes(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 360 GetDefaultMembers Searches for the members defined for the current Type whose DefaultMemberAttribute is set.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 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 methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetEvent(String) Returns the EventInfo object representing the specified public event.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetEvent(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 360 GetEvents() Returns all the public events that are declared or inherited by the current Type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetEvents(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 360 GetField(String) Searches for the public field with the specified name.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetField(String, BindingFlags) Searches for the specified field, using the specified binding constraints.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetFields() Returns all the public fields of the current Type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetFields(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 360 GetGenericArguments Returns 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 360 GetGenericParameterConstraints Returns an array of Type objects that represent the constraints on the current generic type parameter.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetGenericTypeDefinition Returns 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 360 GetHashCode Returns the hash code for this instance. (Overrides Object.GetHashCode().)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetInterface When 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 360 GetInterfaceMap Returns an interface mapping for the specified interface type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetInterfaces When 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 360 GetMember(String) Searches for the public members with the specified name.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetMember(String, BindingFlags) Searches for the specified members, using the specified binding constraints.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetMember(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 360 GetMembers() Returns all the public members of the current Type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetMembers(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 360 GetMethod(String) Searches for the public method with the specified name.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetMethod(String, BindingFlags) Searches for the specified method, using the specified binding constraints.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetMethod(String, array<Type[]) Searches for the specified public method whose parameters match the specified argument types.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetMethod(String, array<Type[], array<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 360 GetMethod(String, BindingFlags, Binder, array<Type[], array<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 360 GetMethod(String, BindingFlags, Binder, CallingConventions, array<Type[], array<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 360 GetMethodImpl When 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 360 GetMethods() Returns all the public methods of the current Type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetMethods(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 360 GetNestedType When 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 360 GetNestedTypes When 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 360 GetProperties() Returns all the public properties of the current Type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetProperties(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 360 GetProperty(String) Searches for the public property with the specified name.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetProperty(String, BindingFlags) Searches for the specified property, using the specified binding constraints.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetProperty(String, Type) Searches for the public property with the specified name and return type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetProperty(String, Type, array<Type[]) Searches for the specified public property whose parameters match the specified argument types.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetProperty(String, Type, array<Type[], array<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 360 GetProperty(String, BindingFlags, Binder, Type, array<Type[], array<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 360 GetPropertyImpl When 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 360 GetType() Gets the current Type.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetType(String) Gets the Type with the specified name, performing a case-sensitive search.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetType(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 360 GetType(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 360 GetTypeCode Gets the underlying type code of the specified Type.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetTypeFromHandle Gets the type referenced by the specified type handle.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetTypeHandle Gets the handle for the Type of a specified object.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 HasElementTypeImpl When 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 360 InvokeMember(String, BindingFlags, Binder, Object, array<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 360 InvokeMember(String, BindingFlags, Binder, Object, array<Object[], array<ParameterModifier[], CultureInfo, array<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 360 IsArrayImpl When 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 360 IsAssignableFrom Determines 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 360 IsByRefImpl When 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 360 IsCOMObjectImpl When 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 360 IsDefined When 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 360 IsInstanceOfType Determines whether the specified object is an instance of the current Type.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 IsPointerImpl When 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 360 IsPrimitiveImpl When 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 360 IsSubclassOf Determines 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 360 IsValueTypeImpl Implements 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 360 MakeArrayType() 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 360 MakeArrayType(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 360 MakeByRefType Returns 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 360 MakeGenericType Substitutes 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 360 MakePointerType Returns a Type object that represents a pointer to the current type.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 ToString Returns a String representing the name of the current Type. (Overrides Object.ToString().)

Top

Fields

  Name Description
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Delimiter Separates names in the namespace of the Type. This field is read-only.
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 EmptyTypes Represents an empty array of type Type. This field is read-only.
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 FilterNameIgnoreCase Represents the case-insensitive member filter used on names. This field is read-only.
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Missing Represents a missing value in the Type information. This field is read-only.

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.

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

Examples

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".
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".
 */

Version Information

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

Platforms

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

Thread Safety

This type is thread safe.