Class Type
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.
Implements
Inherited Members
Namespace: System
Assembly: mscorlib.dll
Syntax
public abstract class Type : MemberInfo, IReflect
Remarks
Available only in mscorlib build with support for System.Reflection.
Constructors
Type()
Declaration
protected Type()
Properties
Assembly
Gets the Assembly in which the type is declared. For generic types, gets the Assembly in which the generic type is defined.
Declaration
public abstract Assembly Assembly { get; }
Property Value
Type | Description |
---|---|
Assembly | An Assembly instance that describes the assembly containing the current type. For generic types, the instance describes the assembly that contains the generic type definition, not the assembly that creates and uses a particular constructed type. |
AssemblyQualifiedName
Gets the assembly-qualified name of the type, which includes the name of the assembly from which this Type object was loaded.
Declaration
public abstract string AssemblyQualifiedName { get; }
Property Value
Type | Description |
---|---|
string | The assembly-qualified name of the Type, which includes the name of the assembly from which the Type was loaded, or null if the current instance represents a generic type parameter. |
BaseType
Gets the type from which the current Type directly inherits.
Declaration
public abstract Type BaseType { get; }
Property Value
Type | Description |
---|---|
Type | The Type from which the current Type directly inherits, or null if the current Type represents the Object class or an interface. |
DeclaringType
Gets the type that declares the current nested type or generic type parameter.
Declaration
public override Type DeclaringType { get; }
Property Value
Type | Description |
---|---|
Type | A Type object representing the enclosing type, if the current type is a nested type; or the generic type definition, if the current type is a type parameter of a generic type; or the type that declares the generic method, if the current type is a type parameter of a generic method; otherwise, null. |
Overrides
FullName
Gets the fully qualified name of the type, including its namespace but not its assembly.
Declaration
public abstract string FullName { get; }
Property Value
Type | Description |
---|---|
string | The fully qualified name of the type, including its namespace but not its assembly; or null if the current instance represents a generic type parameter, an array type, pointer type, or byref type based on a type parameter, or a generic type that is not a generic type definition but contains unresolved type parameters. |
IsAbstract
Gets a value indicating whether the Type is abstract and must be overridden.
Declaration
public bool IsAbstract { get; }
Property Value
Type | Description |
---|---|
bool | true if the Type is abstract; otherwise, false. |
IsArray
Gets a value that indicates whether the type is an array.
Declaration
public bool IsArray { get; }
Property Value
Type | Description |
---|---|
bool | true if the current type is an array; otherwise, false. |
IsClass
Gets a value indicating whether the Type is a class or a delegate; that is, not a value type or interface.
Declaration
public bool IsClass { get; }
Property Value
Type | Description |
---|---|
bool | true if the Type is a class; otherwise, false. |
IsEnum
Gets a value indicating whether the current Type represents an enumeration.
Declaration
public bool IsEnum { get; }
Property Value
Type | Description |
---|---|
bool | true if the current Type represents an enumeration; otherwise, false. |
IsInterface
Gets a value indicating whether the Type is an interface; that is, not a class or a value type.
Declaration
public bool IsInterface { get; }
Property Value
Type | Description |
---|---|
bool | true if the Type is an interface; otherwise, false. |
IsNotPublic
Gets a value indicating whether the Type is not declared public.
Declaration
public bool IsNotPublic { get; }
Property Value
Type | Description |
---|---|
bool | true if the Type is not declared public and is not a nested type; otherwise, false. |
IsPublic
Gets a value indicating whether the Type is declared public.
Declaration
public bool IsPublic { get; }
Property Value
Type | Description |
---|---|
bool | true if the Type is declared public and is not a nested type; otherwise, false. |
IsSerializable
Gets a value indicating whether the Type is serializable.
Declaration
public bool IsSerializable { get; }
Property Value
Type | Description |
---|---|
bool | true if the Type is serializable; otherwise, false. |
IsValueType
Gets a value indicating whether the Type is a value type.
Declaration
public bool IsValueType { get; }
Property Value
Type | Description |
---|---|
bool | true if the Type is a value type; otherwise, false. |
Methods
GetConstructor(Type[])
Searches for a public instance constructor whose parameters match the types in the specified array.
Declaration
public ConstructorInfo GetConstructor(Type[] types)
Parameters
Type | Name | Description |
---|---|---|
Type[] | types | An array of Type objects representing the number, order, and type of the parameters for the desired constructor. -or- An empty array of Type objects, to get a constructor that takes no parameters.Such an empty array is provided by the static field Type.EmptyTypes. |
Returns
Type | Description |
---|---|
ConstructorInfo | An object representing the public instance constructor whose parameters match the types in the parameter type array, if found; otherwise, null. |
GetConstructors()
Returns all the public constructors defined for the current Type.
Declaration
public ConstructorInfo[] GetConstructors()
Returns
Type | Description |
---|---|
ConstructorInfo[] | An array of ConstructorInfo objects representing all the public instance constructors defined for the current Type, but not including the type initializer (static constructor). If no public instance constructors are defined for the current Type, or if the current Type represents a type parameter in the definition of a generic type or generic method, an empty array of type ConstructorInfo is returned. |
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.
Declaration
public abstract Type GetElementType()
Returns
Type | Description |
---|---|
Type | The Type of the object encompassed or referred to by the current array, pointer, or reference type, or null if the current Type is not an array or a pointer, or is not passed by reference, or represents a generic type or a type parameter in the definition of a generic type or generic method. |
GetField(string)
Searches for the public field with the specified name.
Declaration
public FieldInfo GetField(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The string containing the name of the data field to get. |
Returns
Type | Description |
---|---|
FieldInfo | An object representing the public field with the specified name, if found; otherwise, null. |
GetField(string, BindingFlags)
Searches for the specified field, using the specified binding constraints.
Declaration
public abstract FieldInfo GetField(string name, BindingFlags bindingAttr)
Parameters
Type | Name | Description |
---|---|---|
string | name | The string containing the name of the data field to get. |
BindingFlags | bindingAttr | A bitmask comprised of one or more BindingFlags that specify how the search is conducted or Zero, to return null. |
Returns
Type | Description |
---|---|
FieldInfo | An object representing the field that matches the specified requirements, if found; otherwise, null. |
GetFields()
Returns all the public fields of the current Type.
Declaration
public FieldInfo[] GetFields()
Returns
Type | Description |
---|---|
FieldInfo[] | An array of FieldInfo objects representing all the public fields defined for the current Type. -or- An empty array of type FieldInfo, if no public fields are defined for the current Type. |
GetFields(BindingFlags)
When overridden in a derived class, searches for the fields defined for the current Type, using the specified binding constraints.
Declaration
public abstract FieldInfo[] GetFields(BindingFlags bindingAttr)
Parameters
Type | Name | Description |
---|---|---|
BindingFlags | bindingAttr | A bitmask comprised of one or more BindingFlags that specify how the search is conducted or Zero, to return null. |
Returns
Type | Description |
---|---|
FieldInfo[] | An array of FieldInfo objects representing all the public fields defined for the current Type. -or- An empty array of type FieldInfo, if no public fields are defined for the current Type. |
GetInterfaces()
When overridden in a derived class, gets all the interfaces implemented or inherited by the current Type.
Declaration
public abstract Type[] GetInterfaces()
Returns
Type | Description |
---|---|
Type[] | An array of Type objects representing all the interfaces implemented or inherited by the current Type. -or- An empty array of type Type, if no interfaces are implemented or inherited by the current Type. |
GetMethod(string)
Searches for the public method with the specified name.
Declaration
public MethodInfo GetMethod(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The string containing the name of the public method to get. |
Returns
Type | Description |
---|---|
MethodInfo | An object that represents the public method with the specified name, if found; otherwise, null. |
GetMethod(string, BindingFlags)
Searches for the specified method, using the specified binding constraints.
Declaration
public MethodInfo GetMethod(string name, BindingFlags bindingAttr)
Parameters
Type | Name | Description |
---|---|---|
string | name | The string containing the name of the method to get. |
BindingFlags | bindingAttr | A bitmask comprised of one or more BindingFlags that specify how the search is conducted or Zero, to return null. |
Returns
Type | Description |
---|---|
MethodInfo | An object representing the method that matches the specified requirements, if found; otherwise, null. |
GetMethod(string, Type[])
Searches for the specified public method whose parameters match the specified argument types.
Declaration
public MethodInfo GetMethod(string name, Type[] types)
Parameters
Type | Name | Description |
---|---|---|
string | name | The string containing the name of the public method to get. |
Type[] | types | An array of Type objects representing the number, order, and type of the parameters for the desired constructor. -or- An empty array of Type objects, to get a constructor that takes no parameters.Such an empty array is provided by the static field Type.EmptyTypes. |
Returns
Type | Description |
---|---|
MethodInfo | An object representing the public method whose parameters match the specified argument types, if found; otherwise, null. |
GetMethods()
Returns all the public methods of the current Type.
Declaration
public MethodInfo[] GetMethods()
Returns
Type | Description |
---|---|
MethodInfo[] | An array of MethodInfo objects representing all the public methods defined for the current Type. -or- An empty array of type MethodInfo, if no public methods are defined for the current Type. |
GetMethods(BindingFlags)
When overridden in a derived class, searches for the methods defined for the current Type, using the specified binding constraints.
Declaration
public abstract MethodInfo[] GetMethods(BindingFlags bindingAttr)
Parameters
Type | Name | Description |
---|---|---|
BindingFlags | bindingAttr | A bitmask comprised of one or more BindingFlags that specify how the search is conducted or Zero, to return null. |
Returns
Type | Description |
---|---|
MethodInfo[] | An array of MethodInfo objects representing all the public methods defined for the current Type. -or- An empty array of type MethodInfo, if no public methods are defined for the current Type. |
GetType(string)
Gets the Type with the specified name, performing a case-sensitive search.
Declaration
public static Type GetType(string typeName)
Parameters
Type | Name | Description |
---|---|---|
string | typeName | The assembly-qualified name of the type to get. See AssemblyQualifiedName. If the type is in the currently executing assembly or in Mscorlib.dll, it is sufficient to supply the type name qualified by its namespace. |
Returns
Type | Description |
---|---|
Type | The type with the specified name, if found; otherwise, null. |
GetTypeFromHandle(RuntimeTypeHandle)
Gets the type referenced by the specified type handle.
Declaration
public static Type GetTypeFromHandle(RuntimeTypeHandle handle)
Parameters
Type | Name | Description |
---|---|---|
RuntimeTypeHandle | handle | The object that refers to the type. |
Returns
Type | Description |
---|---|
Type | The type referenced by the specified RuntimeTypeHandle, or null if the Value property of handle is null. |
InvokeMember(string, BindingFlags, Binder, object, object[])
Invokes the specified member, using the specified binding constraints and matching the specified argument list.
Declaration
public object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args)
Parameters
Type | Name | Description |
---|---|---|
string | name | The string containing the name of the constructor, method, property, or field member to invoke. -or- An empty string ("") to invoke the default member. -or- For IDispatch members, a string representing the DispID, for example "[DispID=3]". |
BindingFlags | invokeAttr | A bitmask comprised of one or more BindingFlags that specify how the search is conducted. The access can be one of the BindingFlags such as Public, NonPublic, Private, InvokeMethod, GetField, and so on. The type of lookup need not be specified. If the type of lookup is omitted, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static are used. |
Binder | binder | An object that defines a set of properties and enables binding, which can involve selection of an overloaded method, coercion of argument types, and invocation of a member through reflection. -or- A null reference(Nothing in Visual Basic), to use the DefaultBinder.Note that explicitly defining a Binder object may be required for successfully invoking method overloads with variable arguments. |
object | target | The object on which to invoke the specified member. |
object[] | args | An array containing the arguments to pass to the member to invoke. |
Returns
Type | Description |
---|---|
object | An object representing the return value of the invoked member. |
IsInstanceOfType(object)
Determines whether the specified object is an instance of the current Type.
Declaration
public virtual bool IsInstanceOfType(object o)
Parameters
Type | Name | Description |
---|---|---|
object | o | The object to compare with the current type. |
Returns
Type | Description |
---|---|
bool | true if the current Type is in the inheritance hierarchy of the object represented by o, or if the current Type is an interface that o implements. false if neither of these conditions is the case, if o is null, or if the current Type is an open generic type (that is, ContainsGenericParameters returns true). |
IsSubclassOf(Type)
Determines whether the current Type derives from the specified Type.
Declaration
public virtual bool IsSubclassOf(Type c)
Parameters
Type | Name | Description |
---|---|---|
Type | c | The type to compare with the current type. |
Returns
Type | Description |
---|---|
bool | true if the current Type derives from c; otherwise, false. This method also returns false if c and the current Type are equal. |
ToString()
Returns a String representing the name of the current Type.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A String representing the name of the current Type. |