System.Type Class

public abstract class Type : Object

Base Types

Object
  MemberInfo (excluded)
    Type

Assembly

mscorlib

Library

BCL

Summary

Provides information about a type.

Description

The Type class is abstract, as is the MemberInfo class and its subclasses FieldInfo, PropertyInfo, MethodBase, and EventInfo. ConstructorInfo and MethodInfo are subclasses of MethodBase. The runtime provides non-public implementations of these classes. [Note: For example, System.Type.GetMethod(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Reflection.CallingConventions,System.Type[],System.Reflection.ParameterModifier[]) is typed as returning a MethodInfo object. The returned object is actually an instance of the non-public runtime type that implements MethodInfo .]

A conforming CLI program which is written to run on only the Kernel profile cannot subclass Type. [Note: This only applies to conforming programs not conforming implementations.]

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.

[Note: An instance of Type can represent any one of the following types:

The following table shows what members of a base class are returned by the methods that return members of types, such as System.Type.GetConstructor(System.Reflection.BindingFlags,System.Reflection.Binder,System.Reflection.CallingConventions,System.Type[],System.Reflection.ParameterModifier[]) and System.Type.GetMethod(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Reflection.CallingConventions,System.Type[],System.Reflection.ParameterModifier[]).

Member TypeStatic
ConstructorNo
FieldNo
EventNot applicable
MethodNo
Nested TypeNo
PropertyNot applicable

For reflection, properties and events are hide-by-name-and-signature. If a property has both a get and a set accessor in the base class, but the derived class has only a get accessor, the derived class property hides the base class property, and the setter on the base class will not be accessible.

]

See Also

System Namespace

Members

Type Constructors

Type Constructor

Type Methods

Type.Equals Method
Type.GetArrayRank Method
Type.GetAttributeFlagsImpl Method
Type.GetConstructor(System.Reflection.BindingFlags, System.Reflection.Binder, System.Type[], System.Reflection.ParameterModifier[]) Method
Type.GetConstructor(System.Type[]) Method
Type.GetConstructors(System.Reflection.BindingFlags) Method
Type.GetConstructors() Method
Type.GetDefaultMembers Method
Type.GetElementType Method
Type.GetEvent(System.String, System.Reflection.BindingFlags) Method
Type.GetEvent(System.String) Method
Type.GetEvents(System.Reflection.BindingFlags) Method
Type.GetEvents() Method
Type.GetField(System.String, System.Reflection.BindingFlags) Method
Type.GetField(System.String) Method
Type.GetFields(System.Reflection.BindingFlags) Method
Type.GetFields() Method
Type.GetHashCode Method
Type.GetInterface(System.String, bool) Method
Type.GetInterface(System.String) Method
Type.GetInterfaces Method
Type.GetMember(System.String, System.Reflection.BindingFlags) Method
Type.GetMember(System.String) Method
Type.GetMembers(System.Reflection.BindingFlags) Method
Type.GetMembers() Method
Type.GetMethod(System.String, System.Reflection.BindingFlags) Method
Type.GetMethod(System.String, System.Reflection.BindingFlags, System.Reflection.Binder, System.Type[], System.Reflection.ParameterModifier[]) Method
Type.GetMethod(System.String, System.Type[], System.Reflection.ParameterModifier[]) Method
Type.GetMethod(System.String, System.Type[]) Method
Type.GetMethod(System.String) Method
Type.GetMethods(System.Reflection.BindingFlags) Method
Type.GetMethods() Method
Type.GetNestedType(System.String, System.Reflection.BindingFlags) Method
Type.GetNestedType(System.String) Method
Type.GetNestedTypes(System.Reflection.BindingFlags) Method
Type.GetNestedTypes() Method
Type.GetProperties(System.Reflection.BindingFlags) Method
Type.GetProperties() Method
Type.GetProperty(System.String, System.Reflection.BindingFlags, System.Reflection.Binder, System.Type, System.Type[], System.Reflection.ParameterModifier[]) Method
Type.GetProperty(System.String, System.Reflection.BindingFlags) Method
Type.GetProperty(System.String, System.Type, System.Type[]) Method
Type.GetProperty(System.String, System.Type[]) Method
Type.GetProperty(System.String, System.Type) Method
Type.GetProperty(System.String) Method
Type.GetPropertyImpl Method
Type.GetType(System.String, bool, bool) Method
Type.GetType(System.String, bool) Method
Type.GetType(System.String) Method
Type.GetTypeArray Method
Type.GetTypeFromHandle Method
Type.GetTypeHandle Method
Type.HasElementTypeImpl Method
Type.InvokeMember(System.String, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object, System.Object[], System.Reflection.ParameterModifier[], System.Globalization.CultureInfo, System.String[]) Method
Type.InvokeMember(System.String, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object, System.Object[], System.Globalization.CultureInfo) Method
Type.InvokeMember(System.String, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object, System.Object[]) Method
Type.IsArrayImpl Method
Type.IsAssignableFrom Method
Type.IsByRefImpl Method
Type.IsCOMObjectImpl Method
Type.IsInstanceOfType Method
Type.IsPointerImpl Method
Type.IsPrimitiveImpl Method
Type.IsSubclassOf Method
Type.ToString Method

Type Fields

Type.Delimiter Field
Type.EmptyTypes Field
Type.Missing Field

Type Properties

Type.Assembly Property
Type.AssemblyQualifiedName Property
Type.Attributes Property
Type.BaseType Property
Type.DeclaringType Property
Type.DefaultBinder Property
Type.FullName Property
Type.HasElementType Property
Type.IsAbstract Property
Type.IsArray Property
Type.IsAutoLayout Property
Type.IsByRef Property
Type.IsClass Property
Type.IsEnum Property
Type.IsExplicitLayout Property
Type.IsImport Property
Type.IsInterface Property
Type.IsLayoutSequential Property
Type.IsMarshalByRef Property
Type.IsNestedAssembly Property
Type.IsNestedFamANDAssem Property
Type.IsNestedFamORAssem Property
Type.IsNestedFamily Property
Type.IsNestedPrivate Property
Type.IsNestedPublic Property
Type.IsNotPublic Property
Type.IsPointer Property
Type.IsPrimitive Property
Type.IsPublic Property
Type.IsSealed Property
Type.IsSpecialName Property
Type.IsValueType Property
Type.Module Property
Type.Namespace Property
Type.ReflectedType Property
Type.TypeHandle Property
Type.TypeInitializer Property
Type.UnderlyingSystemType Property


Type Constructor

protected Type();

Summary

Constructs a new instance of the Type class.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.Equals Method

public bool Equals(Type o);

Summary

Determines if the underlying system type of the current Type is the same as the underlying system type of the specified Type.

Parameters

o
The Type whose underlying system type is to be compared with the underlying system type of the current Type.

Return Value

true if the underlying system type of o is the same as the underlying system type of the current Type; otherwise, false .

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetArrayRank Method

public virtual int GetArrayRank();

Summary

Returns the number of dimensions in the current Type.

Return Value

A Int32 containing the number of dimensions in the current Type.

Exceptions

Exception TypeCondition
ArgumentExceptionThe current Type is not an array.

See Also

System.Type Class, System Namespace

Type.GetAttributeFlagsImpl Method

protected abstract TypeAttributes GetAttributeFlagsImpl();

Summary

When overridden in a derived type implements the System.Type.Attributes property and returns the attributes specified for the type represented by the current instance.

Return Value

A TypeAttributes value that signifies the attributes of the type represented by the current instance.

Description

[Behaviors: This property is read-only.

This method returns a TypeAttributes value that indicates the attributes set in the metadata of the type represented by the current instance.

]

[Usage: Use this property to determine the visibility, semantics, and layout format of the type represented by the current. Also use this property to determine if the type represented by the current instance has a special name.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetConstructor(System.Reflection.BindingFlags, System.Reflection.Binder, System.Type[], System.Reflection.ParameterModifier[]) Method

public ConstructorInfo GetConstructor(BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers);

Summary

Returns a constructor defined in the type represented by the current instance. The parameters of the constructor match the specified argument types and modifiers, under the specified binding constraints.

Parameters

bindingAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns null.

binder
A Binder object that defines a set of properties and enables the binding, coercion of argument types, and invocation of members using reflection. Specify null to use the System.Type.DefaultBinder .

types
An array of Type objects. The elements in the array are of the same number, in the same order, and represent the same types as the parameters for the constructor to be returned.

modifiers
The only defined value for this parameter is null .

Return Value

A ConstructorInfo object that reflects the constructor that matches the specified criteria. If an exact match does not exist, binder will attempt to coerce the parameter types specified in types to select a match. If binder is unable to select a match, returns null . If the type represented by the current instance is contained in a loaded assembly, the constructor that matches the specified criteria is not public, and the caller does not have sufficient permissions, returns null .

Exceptions

Exception TypeCondition
ArgumentNullExceptiontypes is null , or at least one of the elements in types is null .

ArgumentExceptiontypes has more than one dimension.

Description

The following BindingFlags are used to define which constructors to include in the search:

[Note: For more information, see BindingFlags.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetConstructor(System.Type[]) Method

public ConstructorInfo GetConstructor(Type[] types);

Summary

Returns a public instance constructor defined in the type represented by the current instance. The parameters of the constructor match the specified argument types.

Parameters

types
An array of Type objects. The elements in the array are of the same number, in the same order, and represent the same types as the parameters for the constructor to be returned. Specify System.Type.EmptyTypes to obtain a constructor that takes no parameters.

Return Value

A ConstructorInfo object representing the public instance constructor whose parameters match exactly the types in types , if found; otherwise, null . If the type represented by the current instance is contained in a loaded assembly, the constructor that matches the specified criteria is not public, and the caller does not have sufficient permissions, returns null .

Exceptions

Exception TypeCondition
ArgumentNullExceptiontypes is null , or at least one of the elements in types is null .

ArgumentExceptiontypes has more than one dimension.

Description

This version of System.Type.GetConstructor(System.Reflection.BindingFlags,System.Reflection.Binder,System.Reflection.CallingConventions,System.Type[],System.Reflection.ParameterModifier[]) is equivalent to System.Type.GetConstructor(System.Reflection.BindingFlags,System.Reflection.Binder,System.Reflection.CallingConventions,System.Type[],System.Reflection.ParameterModifier[])(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null , types, null ).

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetConstructors(System.Reflection.BindingFlags) Method

public abstract ConstructorInfo[] GetConstructors(BindingFlags bindingAttr);

Summary

Returns an array of constructors defined in the type represented by the current instance, under the specified binding constraints.

Parameters

bindingAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns null .

Return Value

An array of ConstructorInfo objects that reflect the constructors that are defined in the type represented by the current instance and match the constraints of bindingAttr. If System.Reflection.BindingFlags.NonPublic and System.Reflection.BindingFlags.Static are specified, this array includes the type initializer if it is defined. If no constructors meeting the constraints of bindingAttr are defined in the type represented by the current instance, returns an empty array. If the type represented by the current instance is contained in a loaded assembly, the constructors that match the specified criteria are not public, and the caller does not have sufficient permission, returns null .

Description

The following BindingFlags are used to define which constructors to include in the search:

[Note: For more information, see BindingFlags.]

[Behaviors: As described above.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetConstructors() Method

public ConstructorInfo[] GetConstructors();

Summary

Returns an array of the public constructors defined in the type represented by the current instance.

Return Value

An array of ConstructorInfo objects that reflect the public constructors defined in the type represented by the current instance. If no public constructors are defined in the type represented by the current instance, returns an empty array.

Description

This version of System.Type.GetConstructors is equivalent to System.Type.GetConstructors(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetDefaultMembers Method

public virtual MemberInfo[] GetDefaultMembers();

Summary

Returns an array of MemberInfo objects that reflect the default members defined in the type represented by the current instance.

Return Value

An array of MemberInfo objects reflecting the default members of the type represented by the current instance. If the type represented by the current instance does not have any default members, returns an empty array.

Description

[Behaviors: The members returned by this method have the DefaultMemberAttribute attribute.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetElementType Method

public abstract Type GetElementType();

Summary

Returns the element type of the current Type .

Return Value

A Type that represents the type used to create the current instance if the current instance represents an array, pointer, or an argument passed by reference. Otherwise, returns null .

Example

The following example demonstrates the System.Type.GetElementType method.

using System;
class TestType {
 public static void Main() {
 int[] array = {1,2,3};
 Type t = array.GetType();
 Type t2 = t.GetElementType();
 Console.WriteLine("{0} element type is {1}",array, t2.ToString());

 TestType newMe = new TestType();
 t = newMe.GetType();
 t2 = t.GetElementType();
 Console.WriteLine("{0} element type is {1}", newMe, t2==null? "null" : t2.ToString());
 }
}
The output is

System.Int32[] element type is System.Int32

TestType element type is null

See Also

System.Type Class, System Namespace

Type.GetEvent(System.String, System.Reflection.BindingFlags) Method

public abstract EventInfo GetEvent(string name, BindingFlags bindingAttr);

Summary

Returns a EventInfo object reflecting the event that has the specified name, is defined in the type represented by the current instance, and matches the specified binding constraints.

Parameters

name
A String containing the name of the event to be returned.
bindingAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns null.

Return Value

A EventInfo object reflecting the event that is named name, is defined in the type represented by the current instance, and matches the constraints of bindingAttr. If an event matching these criteria is not found, returns null . If the event is not public, the current instance represents a type from a loaded assembly, and the caller does not have sufficient permission, returns null .

Exceptions

Exception TypeCondition
ArgumentNullExceptionname is null .

Description

The following BindingFlags are used to define which events to include in the search:

The following BindingFlags value can be used to change how the search works:

[Note: For more information, see BindingFlags.]

[Behaviors: As described above.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetEvent(System.String) Method

public EventInfo GetEvent(string name);

Summary

Returns a EventInfo object reflecting the public event that has the specified name and is defined in the type represented by the current instance.

Parameters

name
A String containing the name of the public event to be returned.

Return Value

A EventInfo object reflecting the public event that is named name and is defined in the type represented by the current instance, if found; otherwise, null .

Exceptions

Exception TypeCondition
ArgumentNullExceptionname is null .

Description

This version of System.Type.GetEvent(System.String) is equivalent to System.Type.GetEvent(System.String)( name, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public ).

The search for name is case-sensitive.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetEvents(System.Reflection.BindingFlags) Method

public abstract EventInfo[] GetEvents(BindingFlags bindingAttr);

Summary

Returns an array of EventInfo objects that reflect the events that are defined in the type represented by the current instance and match the specified binding constraints.

Parameters

bindingAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns null.

Return Value

An array of EventInfo objects that reflect the events that are defined in the type represented by the current instance and match the constraints of bindingAttr . If no events match these constraints, returns an empty array. If the type reflected by the current instance is from a loaded assembly and the caller does not have permission to reflect on non-public objects in loaded assemblies, returns only public events.

Description

The following BindingFlags are used to define which events to include in the search:

[Note: For more information, see BindingFlags.]

[Behaviors: As described above.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetEvents() Method

public virtual EventInfo[] GetEvents();

Summary

Returns an array of EventInfo objects that reflect the public events defined in the type represented by the current instance.

Return Value

An array of EventInfo objects that reflect the public events defined in the type represented by the current instance. If no public events are defined in the type represented by the current instance, returns an empty array.

Description

[Behaviors: As described above.]

[Default: This version of System.Type.GetEvents is equivalent to System.Type.GetEvents(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Instance).]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetField(System.String, System.Reflection.BindingFlags) Method

public abstract FieldInfo GetField(string name, BindingFlags bindingAttr);

Summary

Returns a FieldInfo object reflecting the field that has the specified name, is defined in the type represented by the current instance, and matches the specified binding constraints.

Parameters

name
A String containing the name of the field to be returned.
bindingAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns null .

Return Value

A FieldInfo object reflecting the field that is named name, is defined in the type represented by the current instance, and matches the constraints of bindingAttr. If a field matching these criteria cannot be found, returns null . If the field is not public, the current type is from a loaded assembly, and the caller does not have sufficient permission, returns null .

Exceptions

Exception TypeCondition
ArgumentNullExceptionname is null .

Description

The following BindingFlags are used to define which fields to include in the search:

The following BindingFlags values can be used to change how the search works:

[Note: For more information, see BindingFlags.]

[Behaviors: As described above.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetField(System.String) Method

public FieldInfo GetField(string name);

Summary

Returns a FieldInfo object reflecting the field that has the specified name and is defined in the type represented by the current instance.

Parameters

name
A String containing the name of the field to be returned.

Return Value

A FieldInfo object reflecting the field that is named name and is defined in the type represented by the current instance, if found; otherwise, null . If the selected field is non-public, the type represented by the current instance is from a loaded assembly and the caller does not have sufficient permission to reflect on non-public objects in loaded assemblies, returns null .

Exceptions

Exception TypeCondition
ArgumentNullExceptionname is null .

Description

The search for name is case-sensitive.

This version of System.Type.GetField(System.String,System.Reflection.BindingFlags) is equivalent to System.Type.GetField(System.String,System.Reflection.BindingFlags)( name, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Instance ).

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetFields(System.Reflection.BindingFlags) Method

public abstract FieldInfo[] GetFields(BindingFlags bindingAttr);

Summary

Returns an array of FieldInfo objects that reflect the fields that are defined in the type represented by the current instance and match the specified binding constraints.

Parameters

bindingAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns null .

Return Value

An array of FieldInfo objects that reflect the fields that are defined in the type represented by the current instance and match the constraints of bindingAttr . If no fields match these constraints, returns an empty array. If the type represented by the current instance is from a loaded assembly and the caller does not have sufficient permission to reflect on non-public objects in loaded assemblies, returns only public fields.

Description

The following BindingFlags are used to define which fields to include in the search:

The following BindingFlags values can be used to change how the search works:

[Note: For more information, see BindingFlags.]

[Behaviors: As described above.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetFields() Method

public FieldInfo[] GetFields();

Summary

Returns an array of FieldInfo objects that reflect the public fields defined in the type represented by the current instance.

Return Value

An array of FieldInfo objects that reflect the public fields defined in the type represented by the current instance. If no public fields are defined in the type represented by the current instance, returns an empty array.

Description

This version of System.Type.GetFields is equivalent to System.Type.GetFields( System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public ).

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetHashCode Method

public override int GetHashCode();

Summary

Generates a hash code for the current instance.

Return Value

A Int32 containing the hash code for this instance.

Description

The algorithm used to generate the hash code is unspecified.

[Note: This method overrides System.Object.GetHashCode .]

See Also

System.Type Class, System Namespace

Type.GetInterface(System.String, bool) Method

public abstract Type GetInterface(string name, bool ignoreCase);

Summary

Returns the specified interface, specifying whether to do a case-sensitive search.

Parameters

name
A String containing the name of the interface to return.
ignoreCase
A Boolean where true indicates that the name search is to be done case-insensitively, and false performs a case-sensitive search.

Return Value

A Type object representing the interface with the specified name, implemented or inherited by the type represented by the instance, if found; otherwise, null .

Exceptions

Exception TypeCondition
ArgumentNullExceptionname is null .

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetInterface(System.String) Method

public Type GetInterface(string name);

Summary

Searches for the interface with the specified name.

Parameters

name
A String containing the name of the interface to get.

Return Value

A Type object representing the interface with the specified name, implemented or inherited by the current Type, if found; otherwise, null .

Exceptions

Exception TypeCondition
ArgumentNullExceptionname is null .

Description

The search for name is case-sensitive.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetInterfaces Method

public abstract Type[] GetInterfaces();

Summary

Returns all interfaces implemented or inherited by the type represented by the current instance.

Return Value

An array of Type objects representing the interfaces implemented or inherited by the type represented by the current instance. If no interfaces are found, returns an empty Type array.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetMember(System.String, System.Reflection.BindingFlags) Method

public virtual MemberInfo[] GetMember(string name, BindingFlags bindingAttr);

Summary

Returns an array of MemberInfo objects that reflect the members defined in the type represented by the current instance that have the specified name and match the specified binding constraints.

Parameters

name
A String containing the name of the member to be returned.
bindingAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns null .

Return Value

An array of MemberInfo objects that reflect the members named name, are defined in the type represented by the current instance and match the constraints of bindingAttr . If no members match these constraints, returns an empty array. If the selected member is non-public, the type reflected by the current instance is from a loaded assembly and the caller does not have sufficient permission to reflect on non-public objects in loaded assemblies, returns null .

Exceptions

Exception TypeCondition
ArgumentNullExceptionname is null .

Description

The following BindingFlags are used to define which members to include in the search:

The following BindingFlags values can be used to change how the search works:

[Note: For more information, see BindingFlags.]

[Behaviors: As described above.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetMember(System.String) Method

public MemberInfo[] GetMember(string name);

Summary

Returns an array of MemberInfo objects that reflect the public members that have the specified name and are defined in the type represented by the current instance.

Parameters

name
A String containing the name of the members to be returned.

Return Value

An array of MemberInfo objects that reflect the public members that are named name and are defined in the type represented by the current instance. If no public members with the specified name are defined in the type represented by the current instance, returns an empty array.

Exceptions

Exception TypeCondition
ArgumentNullExceptionname is null .

Description

This version of System.Type.GetMember(System.String) is equivalent to System.Type.GetMember(System.String)( name, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public ).

The search for name is case-sensitive.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetMembers(System.Reflection.BindingFlags) Method

public abstract MemberInfo[] GetMembers(BindingFlags bindingAttr);

Summary

Returns an array of MemberInfo objects that reflect the members that are defined in the type represented by the current instance and match the specified binding constraints.

Parameters

bindingAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns null .

Return Value

An array of MemberInfo objects that reflect the members defined in the type represented by the current instance that match the constraints of bindingAttr . If no members match these constraints, returns an empty array. If the type represented by the current instance is from a loaded assembly and the caller does not have sufficient permission to reflect on non-public objects in loaded assemblies, returns only public members.

Description

The following BindingFlags are used to define which members to include in the search:

The following BindingFlags values can be used to change how the search works:

[Note: For more information, see BindingFlags.]

[Behaviors: As described above.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetMembers() Method

public MemberInfo[] GetMembers();

Summary

Returns an array of MemberInfo objects that reflect the public members defined in the type represented by the current instance.

Return Value

An array of MemberInfo objects that reflect the public members defined in the type represented by the current instance. If no public members are defined in the type represented by the current instance, returns an empty array.

Description

This version of System.Type.GetMembers is equivalent to System.Type.GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Instance).

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetMethod(System.String, System.Reflection.BindingFlags) Method

public MethodInfo GetMethod(string name, BindingFlags bindingAttr);

Summary

Returns a MethodInfo object that reflects the method that has the specified name and is defined in the type represented by the current instance.

Parameters

name
A String containing the name of the method to be returned.
bindingAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns null .

Return Value

A MethodInfo object that reflects the method that is defined in the type represented by the current instance and matches the specified criteria, if found; otherwise, null .

Exceptions

Exception TypeCondition
AmbiguousMatchExceptionMore than one method matching the specified criteria was found.
ArgumentNullExceptionname is null .

Description

The following BindingFlags are used to define which members to include in the search:

The following BindingFlags values can be used to change how the search works:

[Note: For more information, see BindingFlags.]

This version of System.Type.GetMethod(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Reflection.CallingConventions,System.Type[],System.Reflection.ParameterModifier[]) is equivalent to System.Type.GetMethod(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Reflection.CallingConventions,System.Type[],System.Reflection.ParameterModifier[])(name, bindingAttr , null , null , null ).

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetMethod(System.String, System.Reflection.BindingFlags, System.Reflection.Binder, System.Type[], System.Reflection.ParameterModifier[]) Method

public MethodInfo GetMethod(string name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers);

Summary

Returns a MethodInfo object that reflects the method that matches the specified criteria and is defined in the type represented by the current instance.

Parameters

name
A String containing the name of the method to be returned.
bindingAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns null .

binder
A Binder object that defines a set of properties and enables the binding, coercion of argument types, and invocation of members using reflection. Specify null to use the System.Type.DefaultBinder .

types
An array of Type objects. The elements in the array are of the same number, in the same order, and represent the same types as the parameters for the method to be returned.

modifiers
The only defined value for this parameter is null .

Return Value

A MethodInfo object that reflects the method defined in the type represented by the current instance that matches the specified criteria. If no method matching the specified criteria is found, returns null . If the selected method is non-public, the type reflected by the current instance is from a loaded assembly, and the caller does not have permission to reflect on non-public objects in loaded assemblies, returns null .

Exceptions

Exception TypeCondition
AmbiguousMatchExceptionMore than one method matching the specified criteria was found.
ArgumentNullExceptionname or types is null .

-or-

At least one of the elements in types is null .

ArgumentExceptiontypes has more than one dimension.

Description

The following BindingFlags are used to define which members to include in the search:

The following BindingFlags values can be used to change how the search works:

[Note: For more information, see BindingFlags.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetMethod(System.String, System.Type[], System.Reflection.ParameterModifier[]) Method

public MethodInfo GetMethod(string name, Type[] types, ParameterModifier[] modifiers);

Summary

Returns a MethodInfo object that reflects the public method that has the specified name and is defined in the type represented by the current instance.

Parameters

name
A String containing the name of the public method to be returned.
types
An array of Type objects. The elements in the array are of the same number, in the same order, and represent the same types as the parameters for the method to be returned.

modifiers
The only defined value for this parameter is null .

Return Value

A MethodInfo object reflecting the public method that is defined in the type represented by the current instance and matches the specified criteria, if found; otherwise, null .

Exceptions

Exception TypeCondition
AmbiguousMatchExceptionMore than one method matching the specified criteria was found.
ArgumentNullExceptionname or types is null .

-or-

At least one of the elements in types is null .

ArgumentExceptiontypes has more than one dimension.

Description

The default binder does not process modifier .

The search for name is case-sensitive.

This version of System.Type.GetMethod(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Reflection.CallingConventions,System.Type[],System.Reflection.ParameterModifier[]) is equivalent to System.Type.GetMethod(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Reflection.CallingConventions,System.Type[],System.Reflection.ParameterModifier[]) ( name, System.Reflection.BindingFlags.Public |System.Reflection.BindingFlags.Static |System.Reflection.BindingFlags.Instance , null , types , modifiers).

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetMethod(System.String, System.Type[]) Method

public MethodInfo GetMethod(string name, Type[] types);

Summary

Returns a MethodInfo object that reflects the public method defined in the type represented by the current instance that has the specified name and parameter information.

Parameters

name
A String containing the name of the public method to be returned.
types
An array of Type objects. The elements in the array are of the same number, in the same order, and represent the same types as the parameters for the method to be returned.

Return Value

A MethodInfo object reflecting the public method defined in the type represented by the current instance that matches the specified criteria. If no public method matching the specified criteria is found, returns null .

Exceptions

Exception TypeCondition
AmbiguousMatchExceptionMore than one method matching the specified criteria was found.
ArgumentNullExceptionname or types is null .

-or-

At least one of the elements in types is null .

ArgumentExceptiontypes has more than one dimension.

Description

The search for name is case-sensitive.

This version of System.Type.GetMethod(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Reflection.CallingConventions,System.Type[],System.Reflection.ParameterModifier[]) is equivalent to System.Type.GetMethod(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Reflection.CallingConventions,System.Type[],System.Reflection.ParameterModifier[])(name, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Instance, null , types, null ).

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetMethod(System.String) Method

public MethodInfo GetMethod(string name);

Summary

Returns a MethodInfo object that reflects the public method that has the specified name and is defined in the type represented by the current instance.

Parameters

name
A String containing the name of the public method to be returned.

Return Value

A MethodInfo object reflecting the public method that is defined in the type represented by the current instance and has the specified name, if found; otherwise, null .

Exceptions

Exception TypeCondition
AmbiguousMatchExceptionMore than one method matching the specified criteria was found.
ArgumentNullExceptionname is null .

Description

The search for name is case-sensitive.

This version of System.Type.GetMethod(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Reflection.CallingConventions,System.Type[],System.Reflection.ParameterModifier[]) is equivalent to System.Type.GetMethod(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Reflection.CallingConventions,System.Type[],System.Reflection.ParameterModifier[])(name, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Instance, null , null , null ).

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetMethods(System.Reflection.BindingFlags) Method

public abstract MethodInfo[] GetMethods(BindingFlags bindingAttr);

Summary

Returns an array of MethodInfo objects that reflect the methods defined in the type represented by the current instance that match the specified binding constraints.

Parameters

bindingAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns null .

Return Value

An array of MethodInfo objects reflecting the methods defined in the type represented by the current instance that match the constraints of bindingAttr . If no such methods found, returns an empty array. If the type represented by the current instance is from a loaded assembly and the caller does not have permission to reflect on non-public objects in loaded assemblies, returns only public methods.

Description

The following BindingFlags are used to define which members to include in the search:

The following BindingFlags values can be used to change how the search works:

[Note: For more information, see BindingFlags.]

[Behaviors: As described above.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetMethods() Method

public MethodInfo[] GetMethods();

Summary

Returns the public methods defined in the type represented by the current instance.

Return Value

An array of MethodInfo objects reflecting the public methods defined in the type represented by the current instance under the constraints of bindingAttr. If no methods matching the constraints are found, returns an empty array.

Description

This version of System.Type.GetMethods is equivalent to System.Type.GetMethods( System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public ).

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetNestedType(System.String, System.Reflection.BindingFlags) Method

public abstract Type GetNestedType(string name, BindingFlags bindingAttr);

Summary

Returns a nested types defined in the type represented by the current instance that match the specified binding constraints.

Parameters

name
A String containing the name of the nested type to return. Specify the unqualified name of the nested type. [Note: For example, for a type B nested within A, if typeA represents the type object for A, the correct invocation is typeA.GetNestedType("B").]

bindingAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns null .

Return Value

A Type object representing the nested type that matches the specified criteria, if found; otherwise, null . If the selected nested type is non-public, the current instance represents a type contained in a loaded assembly and the caller does not have sufficient permissions, returns null .

Exceptions

Exception TypeCondition
ArgumentNullExceptionname is null .

Description

The following BindingFlags are used to define which members to include in the search:

The following BindingFlags values can be used to change how the search works:

[Note: For more information, see BindingFlags.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetNestedType(System.String) Method

public Type GetNestedType(string name);

Summary

Returns the public nested type defined in the type represented by the current instance

Parameters

name
A String containing the name of the public nested type to return. Specify the unqualified name of the nested type. [Note: For example, for a type B nested within A, if typeA represents the type object for A, the correct invocation is typeA.GetNestedType("B"). ]

Return Value

A Type object representing the public nested type with the specified name, if found; otherwise, null .

Exceptions

Exception TypeCondition
ArgumentNullExceptionname is null .

Description

The search for name is case-sensitive.

This version of System.Type.GetNestedTypes is equivalent to System.Type.GetNestedTypes(name, System.Reflection.BindingFlags.Public).

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetNestedTypes(System.Reflection.BindingFlags) Method

public abstract Type[] GetNestedTypes(BindingFlags bindingAttr);

Summary

Returns an array containing the nested types defined in the type represented by the current instance that match the specified binding constraints.

Parameters

bindingAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns null .

Return Value

An array of Type objects representing all types nested within the type represented by the current instance that match the specified binding constraints, if any. Otherwise, returns an empty Type array. If the type reflected by the current instance is contained in a loaded assembly, the type that matches the specified criteria is not public, and the caller does not have sufficient permission, returns only public types.

Description

The following BindingFlags are used to define which members to include in the search:

The following BindingFlags values can be used to change how the search works:

[Note: For more information, see BindingFlags.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetNestedTypes() Method

public Type[] GetNestedTypes();

Summary

Returns all the public types nested within the current Type.

Return Value

An array of Type objects representing all public types nested within the type represented by the current instance, if any. Otherwise, returns an empty Type array.

Description

This version of System.Type.GetNestedTypes is equivalent to System.Type.GetNestedTypes(System.Reflection.BindingFlags.Public).

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetProperties(System.Reflection.BindingFlags) Method

public abstract PropertyInfo[] GetProperties(BindingFlags bindingAttr);

Summary

Returns an array of PropertyInfo objects that reflect the properties defined for the type represented by the current instance that match the specified binding constraints.

Parameters

bindingAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns null .

Return Value

An array of PropertyInfo objects that reflect the properties defined in the type represented by the current instance and match the constraints of bindingAttr . If no matching properties are found, returns an empty array. If the type represented by the current instance is from a loaded assembly and the caller does not have permission to reflect on non-public objects in loaded assemblies, returns only public properties.

Description

The following BindingFlags are used to define which members to include in the search:

The following BindingFlags values can be used to change how the search works:

[Note: For more information, see BindingFlags.]

[Behaviors: A property is considered by reflection to be public if it has at least one accessor that is public . Otherwise, the property is not public .]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetProperties() Method

public PropertyInfo[] GetProperties();

Summary

Returns an array of PropertyInfo objects that reflect the public properties defined in the type represented by the current instance.

Return Value

An array of PropertyInfo objects that reflect the public properties defined in the type represented by the current instance. If no public properties are found, returns an empty array.

Description

This version of System.Type.GetProperties(System.Reflection.BindingFlags) is equivalent to System.Type.GetProperties(System.Reflection.BindingFlags)( System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public ).

A property is considered by reflection to be public if it has at least one accessor that is public . Otherwise, the property is considered to be not public .

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetProperty(System.String, System.Reflection.BindingFlags, System.Reflection.Binder, System.Type, System.Type[], System.Reflection.ParameterModifier[]) Method

public PropertyInfo GetProperty(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers);

Summary

Returns a PropertyInfo object that reflects the property defined in the type represented by the current instance that matches the specified search criteria .

Parameters

name
A String containing the name of the property to be returned.
bindingAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns null .

binder
A Binder object that defines a set of properties and enables the binding, coercion of argument types, and invocation of members using reflection. Specify null to use the System.Type.DefaultBinder .

returnType
A Type object that represents the type of the property to be returned.
types
An array of Type objects. The elements in the array are of the same number, in the same order, and represent the same types as the parameters for the indexer to be returned. Specify System.Type.EmptyTypes to obtain a property that is not indexed.

modifiers
The only defined value for this parameter is null .

Return Value

A PropertyInfo object reflecting the property that is defined in the type represented by the current instance and matches the specified criteria. If no matching property is found, returns null . If the type reflected by the current instance is contained in a loaded assembly, the property that matches the specified criteria is not public, and the caller does not have sufficient permission, returns null .

Exceptions

Exception TypeCondition
AmbiguousMatchExceptionMore than one property matching the specified criteria was found.
ArgumentNullExceptionname or types is null , or at least one of the elements in types is null .

ArgumentExceptiontypes has more than one dimension.

Description

The following BindingFlags are used to define which members to include in the search:

The following BindingFlags values can be used to change how the search works:

[Note: For more information, see BindingFlags.]

This version of System.Type.GetProperty(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Type,System.Type[],System.Reflection.ParameterModifier[]) is equivalent to System.Type.GetPropertyImpl(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Type,System.Type[],System.Reflection.ParameterModifier[])(name, bindingAttr, binder, returnType, types, modifiers).

The search for name is case-sensitive.

Different programming languages use different syntax to specify indexed properties. Internally, this property is referred to by the name "Item" in the metadata. Therefore, any attempt to retrieve an indexed property using reflection is required to specify this internal name in order for the PropertyInfo to be returned correctly.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetProperty(System.String, System.Reflection.BindingFlags) Method

public PropertyInfo GetProperty(string name, BindingFlags bindingAttr);

Summary

Returns a PropertyInfo object that reflects the property defined in the type represented by the current instance that matches the specified search criteria.

Parameters

name
A String containing the name of the property to be returned.
bindingAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns null .

Return Value

A PropertyInfo object reflecting the property defined in the type represented by the current instance that matches the specified criteria. If no matching property is found, returns null . If the type reflected by the current instance is contained in a loaded assembly, the property that matches the specified criteria is not public, and the caller does not have sufficient permission, returns null .

Exceptions

Exception TypeCondition
AmbiguousMatchExceptionMore than one property matching the specified criteria was found.
ArgumentNullExceptionname is null .

Description

The following BindingFlags are used to define which members to include in the search:

The following BindingFlags values can be used to change how the search works:

[Note: For more information, see BindingFlags.]

This version of System.Type.GetProperty(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Type,System.Type[],System.Reflection.ParameterModifier[]) is equivalent to System.Type.GetPropertyImpl(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Type,System.Type[],System.Reflection.ParameterModifier[])(name, bindingAttr, null , null , null , null ).

The search for name is case-sensitive.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetProperty(System.String, System.Type, System.Type[]) Method

public PropertyInfo GetProperty(string name, Type returnType, Type[] types);

Summary

Returns a PropertyInfo object that reflects the public property defined in the type represented by the current instance that matches the specified search criteria.

Parameters

name
A String containing the name of the public property to be returned.
returnType
A Type object that represents the type of the public property to be returned.
types
An array of Type objects. The elements in the array are of the same number, in the same order, and represent the same types as the parameters for the indexer to be returned. Specify System.Type.EmptyTypes for a property that is not indexed.

Return Value

A PropertyInfo object reflecting the public property defined in the type represented by the current instance that matches the specified criteria. If no matching property is found, returns null .

Exceptions

Exception TypeCondition
AmbiguousMatchExceptionMore than one property matching the specified criteria was found.
ArgumentNullExceptionname or types is null , or at least one of the elements in types is null .

ArgumentExceptiontypes has more than one dimension.

Description

This version of System.Type.GetProperty(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Type,System.Type[],System.Reflection.ParameterModifier[]) is equivalent to System.Type.GetPropertyImpl(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Type,System.Type[],System.Reflection.ParameterModifier[])(name, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public, null , returnTypes, types, null ).

The search for name is case-sensitive.

Different programming languages use different syntax to specify indexed properties. Internally, this property is referred to by the name "Item" in the metadata. Therefore, any attempt to retrieve an indexed property using reflection is required to specify this internal name in order for the PropertyInfo to be returned correctly.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetProperty(System.String, System.Type[]) Method

public PropertyInfo GetProperty(string name, Type[] types);

Summary

Returns a PropertyInfo object that reflects the public property defined in the type represented by the current instance that matches the specified search criteria.

Parameters

name
A String containing the name of the public property to be returned.
types
An array of Type objects. The elements in the array are of the same number, in the same order, and represent the same types as the parameters for the indexer to be returned. Specify System.Type.EmptyTypes to obtain a property that is not indexed.

Return Value

A PropertyInfo object reflecting the public property defined on the type represented by the current instance that matches the specified criteria. If no matching property is found, returns null .

Exceptions

Exception TypeCondition
AmbiguousMatchExceptionMore than one property matching the specified criteria was found.
ArgumentNullExceptionname or types is null , or at least one of the elements in types is null .

ArgumentExceptiontypes has more than one dimension.

Description

This version of System.Type.GetProperty(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Type,System.Type[],System.Reflection.ParameterModifier[]) is equivalent to System.Type.GetPropertyImpl(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Type,System.Type[],System.Reflection.ParameterModifier[])(name, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public, null , null , types, null ).

The search for name is case-sensitive.

Different programming languages use different syntax to specify indexed properties. Internally, this property is referred to by the name "Item" in the metadata. Therefore, any attempt to retrieve an indexed property using reflection is required to specify this internal name in order for the PropertyInfo to be returned correctly.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetProperty(System.String, System.Type) Method

public PropertyInfo GetProperty(string name, Type returnType);

Summary

Returns a PropertyInfo object that reflects the public property defined in the type represented by the current instance that matches the specified search criteria.

Parameters

name
A String containing the name of the property to be returned.
returnType
A Type object that represents the type of the property to be returned.

Return Value

A PropertyInfo object reflecting the public property defined on the type represented by the current instance that matches the specified criteria. If no matching property is found, returns null .

Exceptions

Exception TypeCondition
AmbiguousMatchExceptionMore than one property matching the specified criteria was found.
ArgumentNullExceptionname is null .

Description

This version of System.Type.GetProperty(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Type,System.Type[],System.Reflection.ParameterModifier[]) is equivalent to System.Type.GetPropertyImpl(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Type,System.Type[],System.Reflection.ParameterModifier[])(name, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public, null , returnType, null , null ).

The search for name is case-sensitive.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetProperty(System.String) Method

public PropertyInfo GetProperty(string name);

Summary

Returns a PropertyInfo object that reflects the public property defined in the type represented by the current instance that has the specified name.

Parameters

name
A String containing the name of the property to be returned.

Return Value

A PropertyInfo object reflecting the public property defined on the type represented by the current instance that has the specified name. If no matching property is found, returns null .

Exceptions

Exception TypeCondition
AmbiguousMatchExceptionMore than one property matching the specified criteria was found.
ArgumentNullExceptionname is null .

Description

This version of System.Type.GetProperty(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Type,System.Type[],System.Reflection.ParameterModifier[]) is equivalent to System.Type.GetPropertyImpl(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Type,System.Type[],System.Reflection.ParameterModifier[])(name, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public, null , null , null , null ).

The search for name is case-sensitive.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetPropertyImpl Method

protected abstract PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers);

Summary

When overridden in a derived class implements the System.Type.GetProperty(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Type,System.Type[],System.Reflection.ParameterModifier[]) method and returns a PropertyInfo object that reflects the property defined in the type represented by the current instance that matches the specified search criteria.

Parameters

name
A String containing the name of the property to be returned.
bindingAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns null .

binder
A Binder object that defines a set of properties and enables the binding, coercion of argument types, and invocation of members using reflection. Specify null to use the System.Type.DefaultBinder .

returnType
A Type object that represents the type of the property to be returned.
types
An array of Type objects. The elements in the array are of the same number, in the same order, and represent the same types as the parameters for the indexer to be returned. Specify System.Type.EmptyTypes to obtain a property that is not indexed.

modifiers
The only defined value for this parameter is null .

Return Value

A PropertyInfo object representing the property that matches the specified search criteria, if found; otherwise, null . If the type reflected by the current instance is from a loaded assembly, the matching property is not public, and the caller does not have permission to reflect on non-public objects in loaded assemblies, returns null .

Exceptions

Exception TypeCondition
AmbiguousMatchExceptionMore than one property matching the specified criteria was found.
ArgumentNullExceptionname or types is null , or at least one of the elements in types is null .

ArgumentExceptiontypes has more than one dimension.

Description

The following BindingFlags are used to define which members to include in the search:

The following BindingFlags values can be used to change how the search works:

[Note: For more information, see BindingFlags.]

[Behaviors: Different programming languages use different syntax to specify indexed properties. Internally, this property is referred to by the name "Item" in the metadata. Therefore, any attempt to retrieve an indexed property using reflection is required to specify this internal name in order for the PropertyInfo to be returned correctly. ]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetType(System.String, bool, bool) Method

public static Type GetType(string typeName, bool throwOnError, bool ignoreCase);

Summary

Returns the Type with the specified name, optionally performing a case-sensitive search and throwing an exception if an error occurs while loading the Type.

Parameters

typeName
A String containing the name of the Type to return.
throwOnError
A Boolean. Specify true to throw a TypeLoadException if an error occurs while loading the Type. Specify false to ignore errors while loading the Type.

ignoreCase
A Boolean. Specify true to perform a case-insensitive search for typeName. Specify false to perform a case-sensitive search for typeName .

Return Value

The Type with the specified name, if found; otherwise, null . If the requested type is non-public and the caller does not have permission to reflect non-public objects outside the current assembly, this method returns null .

Exceptions

Exception TypeCondition
ArgumentNullExceptiontypeName is null .
TargetInvocationExceptionA type initializer was invoked and threw an exception.
TypeLoadExceptionthrowOnError is true and an error was encountered while loading the selected Type.

Description

typeName can be a simple type name, a fully qualified name, or a complex name that includes an assembly name. [Note: System.Type.AssemblyQualifiedName returns a fully qualified type name including nested types and the assembly name. ]

If typeName includes only the name of the Type, this method searches in the calling object's assembly, then in the mscorlib.dll assembly. If typeName is fully qualified with the partial or complete assembly name, this method searches in the specified assembly.

[Note:

The following table shows calls to GetType for various types.

To GetUse
An unmanaged pointer to MyType Type.GetType("MyType*")
An unmanaged pointer to a pointer to MyType Type.GetType("MyType**")
A managed pointer or reference to MyType Type.GetType("MyType&"). Note that unlike pointers, references are limited to one level.
A parent class and a nested classType.GetType("MyParentClass+MyNestedClass")
A one-dimensional array with a lower bound of 0Type.GetType("MyArray[]")
A one-dimensional array with an unknown lower boundType.GetType("MyArray[*]")
An n-dimensional arrayA comma (,) inside the brackets a total of n-1 times. For example, System.Object[,,] represents a three-dimensional Object array.
A two-dimensional array's arrayType.GetType("MyArray[][]")
A rectangular two-dimensional array with unknown lower boundsType.GetType("MyArray[*,*]")or Type.GetType("MyArray[,]")
]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetType(System.String, bool) Method

public static Type GetType(string typeName, bool throwOnError);

Summary

Returns the Type with the specified name, optionally throwing an exception if an error occurs while loading the Type .

Parameters

typeName
A String containing the case-sensitive name of the Type to return.
throwOnError
A Boolean. Specify true to throw a TypeLoadException if an error occurs while loading the Type. Specify false to ignore errors while loading the Type.

Return Value

The Type with the specified name, if found; otherwise, null . If the requested type is non-public and the caller does not have permission to reflect non-public objects outside the current assembly, this method returns null .

Exceptions

Exception TypeCondition
ArgumentNullExceptiontypeName is null .
TargetInvocationExceptionA type initializer was invoked and threw an exception.
TypeLoadExceptionthrowOnError is true and an error was encountered while loading the Type.

Description

This method is equivalent to System.Type.GetType(System.String,System.Boolean,System.Boolean)(name, throwOnError, false ).

typeName can be a simple type name, a fully qualified name, or a complex name that includes an assembly name specification. If typeName includes only the name of the Type, this method searches in the calling object's assembly, then in the mscorlib.dll assembly. If typeName is fully qualified with the partial or complete assembly name, this method searches in the specified assembly.

[Note: System.Type.AssemblyQualifiedName can return a fully qualified type name including nested types and the assembly name. For complete details, see System.Type.GetType(System.String,System.Boolean,System.Boolean)(String, Boolean, Boolean). ]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetType(System.String) Method

public static Type GetType(string typeName);

Summary

Returns the Type with the specified name.

Parameters

typeName
A String containing the case-sensitive name of the Type to return.

Return Value

The Type with the specified name, if found; otherwise, null . If the requested type is non-public and the caller does not have permission to reflect non-public objects outside the current assembly, this method returns null .

Exceptions

Exception TypeCondition
ArgumentNullExceptiontypeName is null .
TargetInvocationExceptionA type initializer was invoked and threw an exception.

Description

This method is equivalent to System.Type.GetType(System.String,System.Boolean,System.Boolean)(name, false , false ).

typeName can be a simple type name, a type name that includes a namespace, or a complex name that includes an assembly name specification. If typeName includes only the name of the Type, this method searches in the calling object's assembly, then in the mscorlib.dll assembly. If typeName is fully qualified with the partial or complete assembly name, this method searches in the specified assembly.

[Note: System.Type.AssemblyQualifiedName can return a fully qualified type name including nested types and the assembly name. For complete details, see System.Type.GetType(System.String,System.Boolean,System.Boolean)(String, Boolean, Boolean).]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetTypeArray Method

public static Type[] GetTypeArray(object[] args);

Summary

Returns the types of the objects in the specified array.

Parameters

args
An array of objects whose types are to be returned.

Return Value

An array of Type objects representing the types of the corresponding elements in args. If a requested type is not public and the caller does not have permission to reflect non-public objects outside the current assembly, the corresponding element in the array returned by this method will be null .

Exceptions

Exception TypeCondition
ArgumentNullExceptionargs is null .
TargetInvocationExceptionThe type initializers were invoked and at least one threw an exception.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.GetTypeFromHandle Method

public static Type GetTypeFromHandle(RuntimeTypeHandle handle);

Summary

Gets the Type referenced by the specified type handle.

Parameters

handle
The RuntimeTypeHandle object that refers to the desired Type.

Return Value

The Type referenced by the specified RuntimeTypeHandle.

Exceptions

Exception TypeCondition
ArgumentNullExceptionhandle is null .
SecurityExceptionThe requested type is non-public and outside the current assembly, and the caller does not have the required permission.
TargetInvocationExceptionA type initializer was invoked and threw an exception.

Description

The handles are valid only in the application domain in which they were obtained.

Library

RuntimeInfrastructure

See Also

System.Type Class, System Namespace

Type.GetTypeHandle Method

public static RuntimeTypeHandle GetTypeHandle(object o);

Summary

Returns the handle for the Type of the specified object.

Parameters

o
The object for which to get the type handle.

Return Value

The RuntimeTypeHandle for the Type of the specified Object.

Description

The handle is valid only in the application domain in which it was obtained.

Library

RuntimeInfrastructure

See Also

System.Type Class, System Namespace

Type.HasElementTypeImpl Method

protected abstract bool HasElementTypeImpl();

Summary

When overridden in a derived class, implements the System.Type.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.

Return Value

true if the Type is an array, a pointer, or is passed by reference; otherwise, false .

Description

[Note: For example, System.Type.GetType(System.String,System.Boolean,System.Boolean) ("System.Int32[]").HasElementTypeImpl returns true , but System.Type.GetType(System.String,System.Boolean,System.Boolean) ("System.Int32").HasElementTypeImpl returns false . System.Type.HasElementTypeImpl also returns true for "System.Int32*" and "System.Int32&".]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.InvokeMember(System.String, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object, System.Object[], System.Reflection.ParameterModifier[], System.Globalization.CultureInfo, System.String[]) Method

public abstract object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters);

Summary

Invokes or accesses a member defined on the type represented by the current instance that matches the specified binding criteria.

Parameters

name
A String containing the name of the constructor or method to invoke, or property or field to access. If the type represented by the current instance has a default member, specify System.String.Empty to invoke that member. [Note: For more information on default members, see DefaultMemberAttribute .]

invokeAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance is used by default.

target
A Object on which to invoke the member that matches the other specified criteria. If the matching member is static , this parameter is ignored.
args
An array of objects containing the arguments to pass to the member to be invoked. The elements of this array are of the same number and in the same order by assignment-compatible type as specified by the contract of the member to be bound if and only if nameParameters is null . If namedParameters is not null , the order of the elements in args corresponds to the order of the parameters specified in namedParameters. Specify an empty array or null for a member that takes no parameters.
modifiers
The only defined value for this parameter is null .

culture
The only defined value for this parameter is null .

namedParameters
An array of String objects containing the names of the parameters to which the values in args are passed. These names are processed in a case-sensitive manner and have a one-to-one correspondence with the elements of args. Specify an empty array or null for a member that takes no parameters. Specify null to have this parameter ignored.

Return Value

A Object containing the return value of the invoked or accessed member. If the member does not have a return value, returns a Object containing Void .

Exceptions

Exception TypeCondition
ArgumentNullExceptionname is null .

ArgumentExceptionargs has more than one dimension.

-or-

invokeAttr is not a valid BindingFlags value.

-or-

The member to be invoked is a constructor and System.Reflection.BindingFlags.CreateInstance is not specified in invokeAttr.

-or-

The member to be invoked is a method that is not a type initializer or instance constructor, and System.Reflection.BindingFlags.InvokeMethod is not specified in invokeAttr.

-or-

The member to be accessed is a field, and neither System.Reflection.BindingFlags.GetField nor System.Reflection.BindingFlags.SetField is specified in invokeAttr.

-or-

The member to be accessed is a property, and neither System.Reflection.BindingFlags.GetProperty nor System.Reflection.BindingFlags.SetProperty is specified in invokeAttr.

-or-

invokeAttr contains System.Reflection.BindingFlags.CreateInstance and at least one of System.Reflection.BindingFlags.InvokeMethod, System.Reflection.BindingFlags.GetField, System.Reflection.BindingFlags.SetField, System.Reflection.BindingFlags.GetProperty, or System.Reflection.BindingFlags.SetProperty.

-or-

invokeAttr contains both System.Reflection.BindingFlags.GetField and System.Reflection.BindingFlags.SetField.

-or-

invokeAttr contains both System.Reflection.BindingFlags.GetProperty and System.Reflection.BindingFlags.SetProperty.

-or-

invokeAttr contains System.Reflection.BindingFlags.InvokeMethod and at least one of System.Reflection.BindingFlags.SetField or System.Reflection.BindingFlags.SetProperty.

-or-

invokeAttr contains System.Reflection.BindingFlags.SetField and args has more than one element.

-or-

namedParameters.Length > args.Length .

-or-

At least one element in namedParameters is null .

-or-

At least one element in args is not assignment-compatible with the corresponding parameter in namedParameters.

MissingFieldExceptionA field or property matching the specified criteria was not found.
MissingMethodExceptionA method matching the specified criteria cannot be found.
MethodAccessExceptionThe requested member is non-public and the caller does not have the required permission.
TargetExceptionThe member matching the specified criteria cannot be invoked on target.
TargetInvocationExceptionThe member matching the specified criteria threw an exception.
AmbiguousMatchExceptionMore than one member matches the specified criteria.

Description

System.Type.InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[]) calls a constructor or a method , gets or sets a property , gets or sets a field, or gets or sets an element of an array.

The binder finds all of the matching members. These members are found based upon the type of binding specified by InvokeAttr . The System.Reflection.Binder.BindToMethod(System.Reflection.BindingFlags,System.Reflection.MethodBase[],System.Object[]@,System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[],System.Object@) is responsible for selecting the method to be invoked. The default binder selects the most specific match. The set of members is then filtered by name, number of arguments, and a set of search modifiers defined in the binder. After the member is selected, it is invoked or accessed. Accessibility is checked at that point. Access restrictions are ignored for fully trusted code; that is, private constructors, methods, fields, and properties can be accessed and invoked via reflection whenever the code is fully trusted.

The following BindingFlags are used to define which members to include in the search:

The following BindingFlags values can be used to change how the search works:

[Note: For more information, see BindingFlags.]

[Behaviors: Each parameter in the namedParameters array is assigned the value in the corresponding element in the args array. If the length of args is greater than the length of namedParameters, the remaining argument values are passed in order.

A member will be found only if the number of parameters in the member declaration equals the number of arguments in the args array (unless default arguments are defined on the member). Also, The type of each argument is required to be convertible by the binder to the type of the parameter.

It is required that the caller specify values for bindingAttr as follows:

ActionBindingFlags
Invoke a constructor. System.Reflection.BindingFlags.CreateInstance. This flag is not valid with the other flags in this table. If this flag is specified, name is ignored.
Invoke a method. System.Reflection.BindingFlags.InvokeMethod. This flag if not valid with System.Reflection.BindingFlags.CreateInstance, System.Reflection.BindingFlags.SetField, or System.Reflection.BindingFlags.SetProperty.
Define a field value. System.Reflection.BindingFlags.SetField. This flag is not valid with System.Reflection.BindingFlags.CreateInstance, System.Reflection.BindingFlags.InvokeMethod, or System.Reflection.BindingFlags.GetField.
Return a field value. System.Reflection.BindingFlags.GetField. This flag is not valid with System.Reflection.BindingFlags.CreateInstance, System.Reflection.BindingFlags.InvokeMethod, or System.Reflection.BindingFlags.SetField.
Set a property. System.Reflection.BindingFlags.SetProperty. This flag is not valid with System.Reflection.BindingFlags.CreateInstance, System.Reflection.BindingFlags.InvokeMethod, or System.Reflection.BindingFlags.GetProperty.
Get a property.System.Reflection.BindingFlags.GetProperty. This flag is not valid with System.Reflection.BindingFlags.CreateInstance, System.Reflection.BindingFlags.InvokeMethod, or System.Reflection.BindingFlags.SetProperty.

[Note: For more information, see BindingFlags .]

]

[Usage: System.Type.InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[]) can be used to invoke methods with parameters that have default values. To bind to these methods, System.Reflection.BindingFlags.OptionalParamBinding must be specified. For a parameter that has a default value, the caller can supply a value or supply System.Type.Missing to use the default value.

System.Type.InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[]) can be used to set a field to a particular value by specifying System.Reflection.BindingFlags.SetField . For example, to set a public instance field named F on class C, where F is a string, the value is set using the following statement:

typeof(C).InvokeMember("F", BindingFlags.SetField, null, C, new Object{ "strings new value"}, null, null, null);

A string array F can be initialized as follows:

typeof(C).InvokeMember("F", BindingFlags.SetField, null, C, new Object{new String[]{"a","z","c","d"}, null, null, null);

Use System.Type.InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[]) to set the value of an element in an array by specifying the index of the value and the new value for the element as follows:

typeof(C).InvokeMember("F", BindingFlags.SetField, null, C, new Object{1, "b"}, null, null, null);

The preceding statement changes "z" in array F to "b".

]

Example

The following example demonstrates the use of System.Type.InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[]) to construct a String, obtain its System.String.Length property, invoke System.String.Insert(System.Int32,System.String) on it, and then set its value using the System.String.Empty field.

using System;
using System.Reflection;

class InvokeMemberExample
{
   static void Main(string[] args)
   {
      // Create the parameter arrays that will
      // be passed to InvokeMember.
      char[] cAry = 
      new char[] {'A',' ','s','t','r','i','n','g'};
      object[] oAry = new object[] {cAry, 0, cAry.Length};

      Type t = typeof(string);

      // Invoke the constructor of a string.
      string str =
         (string)t.InvokeMember(null, BindingFlags.Instance |
         BindingFlags.Public | BindingFlags.CreateInstance, null,
         null, oAry, null, null, null);
      Console.WriteLine("The string is \"{0}\".", str);

      // Access a property of the string.
      int i =
         (int) t.InvokeMember("Length", BindingFlags.Instance |
         BindingFlags.Public | BindingFlags.GetProperty, null, 
         str, null, null, null, null);
      Console.WriteLine("The length of the string is {0}.", i);

      // Invoke a method on the string.
      string newStr = "new ";
      object[] oAry2 = new Object[] {2, newStr};
      str = (string) t.InvokeMember("Insert", BindingFlags.Instance |
         BindingFlags.Public | BindingFlags.InvokeMethod, null, str, 
         oAry2, null, null, null);
      Console.WriteLine("The modified string is \"{0}\".", str);

      // Access a field of the string.
      str = (string) t.InvokeMember("Empty", BindingFlags.Static | 
         BindingFlags.Public | BindingFlags.GetField, null, str, 
         null);
      Console.WriteLine("The empty string is \"{0}\".", str);
  
   }
}
The output is

The string is "A string".

The length of the string is 8.

The modified string is "A new string"

The empty string is "".

Library

Reflection

See Also

System.Type Class, System Namespace

Type.InvokeMember(System.String, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object, System.Object[], System.Globalization.CultureInfo) Method

public object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, CultureInfo culture);

Summary

Invokes the specified member, using the specified binding constraints and matching the specified argument list and culture.

Parameters

name
A String containing the name of the constructor or method to invoke, or property or field to access. If the type represented by the current instance has a default member, specify System.String.Empty to invoke that member. [Note: For more information on default members, see DefaultMemberAttribute .]

invokeAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance is used by default.

binder
A Binder object that defines a set of properties and enables the binding, coercion of argument types, and invocation of members using reflection. Specify null to use the System.Type.DefaultBinder .

target
A Object on which to invoke the member that matches the other specified criteria. If the matching member is static , this parameter is ignored.
args
An array of objects containing the arguments to pass to the member to be invoked. The elements of this array are of the same number and in the same order by assignment-compatible type as specified by the contract of the member to be bound. Specify an empty array or null for a member that has no parameters.
culture
The only defined value for this parameter is null .

Return Value

A Object containing the return value of the invoked member. If the invoked member does not have a return value, returns a Object containing Void .

Exceptions

Exception TypeCondition
ArgumentNullExceptionname is null .

ArgumentExceptionargs has more than one dimension.

-or-

invokeAttr is not a valid BindingFlags value.

-or-

The member to be invoked is a constructor and System.Reflection.BindingFlags.CreateInstance is not specified in invokeAttr.

-or-

The member to be invoked is a method that is not a type initializer or instance constructor, and System.Reflection.BindingFlags.InvokeMethod is not specified in invokeAttr.

-or-

The member to be accessed is a field, and neither System.Reflection.BindingFlags.GetField nor System.Reflection.BindingFlags.SetField is specified in invokeAttr.

-or-

The member to be accessed is a property, and neither System.Reflection.BindingFlags.GetProperty nor System.Reflection.BindingFlags.SetProperty is specified in invokeAttr.

-or-

invokeAttr contains System.Reflection.BindingFlags.CreateInstance and at least one of System.Reflection.BindingFlags.InvokeMethod, System.Reflection.BindingFlags.GetField, System.Reflection.BindingFlags.SetField, System.Reflection.BindingFlags.GetProperty, or System.Reflection.BindingFlags.SetProperty.

-or-

invokeAttr contains both System.Reflection.BindingFlags.GetField and System.Reflection.BindingFlags.SetField.

-or-

invokeAttr contains both System.Reflection.BindingFlags.GetProperty and System.Reflection.BindingFlags.SetProperty.

-or-

invokeAttr contains System.Reflection.BindingFlags.InvokeMethodand at least one of System.Reflection.BindingFlags.SetField or System.Reflection.BindingFlags.SetProperty.

-or-

invokeAttr contains System.Reflection.BindingFlags.SetField and args has more than one element.

MissingFieldExceptionA field or property matching the specified criteria was not found.
MissingMethodExceptionA method matching the specified criteria was not found.
MethodAccessExceptionThe requested member is non-public and the caller does not have the required permission.
TargetExceptionThe member matching the specified criteria cannot be invoked on target.
TargetInvocationExceptionThe member matching the specified criteria threw an exception.
AmbiguousMatchExceptionMore than one member matches the specified criteria.

Description

This version of System.Type.InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[]) is equivalent to System.Type.InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[])( name, invokeAttr, binder, target, args, null , culture, null ).

Example

For an example that demonstrates System.Type.InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[]) , see System.Type.InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[])( String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]).

Library

Reflection

See Also

System.Type Class, System Namespace

Type.InvokeMember(System.String, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object, System.Object[]) Method

public object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args);

Summary

Invokes the specified member, using the specified binding constraints and matching the specified argument list.

Parameters

name
A String containing the name of the constructor or method to invoke, or property or field to access. If the type represented by the current instance has a default member, specify System.String.Empty to invoke that member. [Note: For more information on default members, see DefaultMemberAttribute .]

invokeAttr
A bitwise combination of BindingFlags values that control the binding process. If zero is specified, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance is used by default.
binder
A Binder object that defines a set of properties and enables the binding, coercion of argument types, and invocation of members using reflection. Specify null to use the System.Type.DefaultBinder .

target
A Object on which to invoke the member that matches the other specified criteria. If the matching member is static , this parameter is ignored.
args
An array of objects containing the arguments to pass to the member to be invoked. The elements of this array are of the same number and in the same order by assignment-compatible type as specified by the contract of the member to be bound. Specify an empty array or null for a member that has no parameters.

Return Value

A Object containing the return value of the invoked member. If the invoked member does not have a return value, returns a Object containing Void .

Exceptions

Exception TypeCondition
ArgumentNullExceptionname is null .

ArgumentExceptionargs has more than one dimension.

-or-

invokeAttr is not a valid BindingFlags value.

-or-

The member to be invoked is a constructor and System.Reflection.BindingFlags.CreateInstance is not specified in invokeAttr.

-or-

The member to be invoked is a method that is not a type initializer or instance constructor, and System.Reflection.BindingFlags.InvokeMethod is not specified in invokeAttr.

-or-

The member to be accessed is a field, and neither System.Reflection.BindingFlags.GetField nor System.Reflection.BindingFlags.SetField is specified in invokeAttr.

-or-

The member to be accessed is a property, and neither System.Reflection.BindingFlags.GetProperty nor System.Reflection.BindingFlags.SetProperty is specified in invokeAttr.

-or-

invokeAttr contains System.Reflection.BindingFlags.CreateInstance and at least one of System.Reflection.BindingFlags.InvokeMethod, System.Reflection.BindingFlags.GetField, System.Reflection.BindingFlags.SetField, System.Reflection.BindingFlags.GetProperty, or System.Reflection.BindingFlags.SetProperty.

-or-

invokeAttr contains both System.Reflection.BindingFlags.GetField and System.Reflection.BindingFlags.SetField.

-or-

invokeAttr contains both System.Reflection.BindingFlags.GetProperty and System.Reflection.BindingFlags.SetProperty.

-or-

invokeAttr contains System.Reflection.BindingFlags.InvokeMethod and at least one of System.Reflection.BindingFlags.SetField or System.Reflection.BindingFlags.SetProperty.

-or-

invokeAttr contains System.Reflection.BindingFlags.SetField and args has more than one element.

MissingFieldExceptionA field or property matching the specified criteria was not found.
MissingMethodExceptionA method matching the specified criteria cannot be found.
MethodAccessExceptionThe requested member is non-public and the caller does not have the required permission.
TargetExceptionThe member matching the specified criteria cannot be invoked on target.
TargetInvocationExceptionThe member matching the specified criteria threw an exception.
AmbiguousMatchExceptionMore than one member matches the specified criteria.

Description

This version of System.Type.InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[]) is equivalent to System.Type.InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[])(name, invokeAttr, binder, target, args, null , null , null ).

[Note: For a demonstration of the use of System.Type.InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[]), see the example for System.Type.InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[])( String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]).]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsArrayImpl Method

protected abstract bool IsArrayImpl();

Summary

When overridden in a derived class implements the System.Type.IsArray property returning a Boolean value that indicates whether the type represented by the current instance is an array.

Return Value

true if the Type is an array; otherwise, false .

Description

An instance of the Array class is required to return false because it is an object, not an array.[Behaviors: As described above.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsAssignableFrom Method

public virtual bool IsAssignableFrom(Type c);

Summary

Determines whether an instance of the current Type can be assigned from an instance of the specified Type .

Parameters

c
The Type to compare with the current Type .

Return Value

false if c is a null reference.

true if one or more of the following statements are true; otherwise false .

Example

The following example demonstrates the System.Type.IsAssignableFrom(System.Type) method using arrays.

using System;
class ArrayTypeTest {
 public static void Main() {
 int i = 1;
 int [] array10 = new int [10];
 int [] array2 = new int[2];
 int [,]array22 = new int[2,2];
 int [,]array24 = new int[2,4];
 int [,,]array333 = new int[3,3,3];
 Type array10Type = array10.GetType();
 Type array2Type = array2.GetType();
 Type array22Type = array22.GetType();
 Type array24Type = array24.GetType();
 Type array333Type = array333.GetType();

 // If X and Y are not both arrays, then false
 Console.WriteLine("int[2] is assignable from int? {0} ", array2Type.IsAssignableFrom(i.GetType()));
 // If X and Y have same type and rank, then true.
 Console.WriteLine("int[2] is assignable from int[10]? {0} ",  array2Type.IsAssignableFrom(array10Type));
 Console.WriteLine("int[2,2] is assignable from int[2,4]? {0}",  array22Type.IsAssignableFrom(array24Type));
 Console.WriteLine("int[2,4] is assignable from int[2,2]? {0}",  array24Type.IsAssignableFrom(array22Type));
 Console.WriteLine("");
 // If X and Y do not have the same rank, then false.
 Console.WriteLine("int[2,2] is assignable from int[10]? {0}",  array22Type.IsAssignableFrom(array10Type));
 Console.WriteLine("int[2,2] is assignable from int[3,3,3]? {0}",  array22Type.IsAssignableFrom(array333Type));
 Console.WriteLine("int[3,3,3] is assignable from int[2,2]? {0}",  array333Type.IsAssignableFrom(array22Type));
 }
}
The output is

int[2] is assignable from int? False

int[2] is assignable from int[10]? True

int[2,2] is assignable from int[2,4]? True

int[2,4] is assignable from int[2,2]? True

int[2,2] is assignable from int[10]? False

int[2,2] is assignable from int[3,3,3]? False

int[3,3,3] is assignable from int[2,2]? False

See Also

System.Type Class, System Namespace

Type.IsByRefImpl Method

protected abstract bool IsByRefImpl();

Summary

When overridden in a derived class, implements the System.Type.IsByRef property and determines whether the Type is passed by reference.

Return Value

true if the Type is passed by reference; otherwise, false .

Description

[Behaviors: As described above.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsCOMObjectImpl Method

protected abstract bool IsCOMObjectImpl();

Summary

Reserved.

Return Value

false

Description

This abstract method is required to be present for legacy implementations. Conforming implementations are permitted to throw the NotSupportedException as their implementation.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsInstanceOfType Method

public virtual bool IsInstanceOfType(object o);

Summary

Determines whether the specified object is an instance of the current Type.

Parameters

o
The object to compare with the current Type.

Return Value

true if either of the following statements is true; otherwise false .

If o is a null reference, returns false .

Description

[Behaviors: As described above.]

Example

The following example demonstrates the System.Type.IsInstanceOfType(System.Object) method.

using System;
public interface IFoo { }
public class MyClass : IFoo {}
public class MyDerivedClass : MyClass {}
class IsInstanceTest {
 public static void Main() {
 Type ifooType=typeof(IFoo);
 MyClass mc = new MyClass();
 Type mcType = mc.GetType();
 MyClass mdc = new MyDerivedClass();
 Type mdcType = mdc.GetType();
 int [] array = new int [10];
 Type arrayType = typeof(Array);
 Console.WriteLine("int[] is instance of Array? {0}", arrayType.IsInstanceOfType(array));
 Console.WriteLine("myclass instance is instance of MyClass? {0}", mcType.IsInstanceOfType(mc));
 Console.WriteLine("myderivedclass instance is instance of MyClass? {0}",  mcType.IsInstanceOfType(mdc));
 Console.WriteLine("myclass instance is instance of IFoo? {0}", ifooType.IsInstanceOfType(mc));
 Console.WriteLine("myderivedclass instance is instance of IFoo? {0}",  ifooType.IsInstanceOfType(mdc));
 }
}
The output is

int[] is instance of Array? True

myclass instance is instance of MyClass? True

myderivedclass instance is instance of MyClass? True

myclass instance is instance of IFoo? True

myderivedclass instance is instance of IFoo? True

See Also

System.Type Class, System Namespace

Type.IsPointerImpl Method

protected abstract bool IsPointerImpl();

Summary

When overridden in a derived class, implements the System.Type.IsPointer property and determines whether the Type is a pointer.

Return Value

true if the Type is a pointer; otherwise, false .

Description

[Behaviors: As described above.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsPrimitiveImpl Method

protected abstract bool IsPrimitiveImpl();

Summary

When overridden in a derived class, implements the System.Type.IsPrimitive property and determines whether the Type is one of the primitive types.

Return Value

true if the Type is one of the primitive types; otherwise, false .

Description

[Behaviors: This method returns true if the underlying type of the current instance is one of the following: Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Char, Double, and Single.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsSubclassOf Method

public virtual bool IsSubclassOf(Type c);

Summary

Determines whether the current Type derives from the specified Type .

Parameters

c
The Type to compare with the current Type.

Return Value

true if c and the current Type represent classes, and the class represented by the current Type derives from the class represented by c; otherwise false . Returns false if c and the current Type represent the same class.

Example

The following example demonstrates the System.Type.IsSubclassOf(System.Type) method.

using System;
public interface IFoo { }
public interface IBar:IFoo{}
public class MyClass : IFoo {}
public class MyDerivedClass : MyClass {}
class IsSubclassTest {
 public static void Main() {
 Type ifooType = typeof(IFoo);
 Type ibarType = typeof(IBar);
 MyClass mc = new MyClass();
 Type mcType = mc.GetType();
 MyClass mdc = new MyDerivedClass();
 Type mdcType = mdc.GetType();
 int [] array = new int [10];
 Type arrayOfIntsType = array.GetType();
 Type arrayType = typeof(Array);
 
 Console.WriteLine("Array is subclass of int[]? {0}", arrayType.IsSubclassOf(arrayOfIntsType));
 Console.WriteLine("int [] is subclass of Array? {0}", arrayOfIntsType.IsSubclassOf(arrayType));
 Console.WriteLine("IFoo is subclass of IBar? {0}", ifooType.IsSubclassOf(ibarType));
 Console.WriteLine("myclass is subclass of MyClass? {0}", mcType.IsSubclassOf(mcType));
 Console.WriteLine("myderivedclass is subclass of MyClass? {0}", mdcType.IsSubclassOf(mcType));
 }
}
The output is

Array is subclass of int[]? False

int [] is subclass of Array? True

IFoo is subclass of IBar? False

myclass is subclass of MyClass? False

myderivedclass is subclass of MyClass? True

See Also

System.Type Class, System Namespace

Type.ToString Method

public override string ToString();

Summary

Returns a String representation of the current Type.

Return Value

Returns System.Type.FullName .

Description

[Note: This method overrides System.Object.ToString .]

See Also

System.Type Class, System Namespace

Type.Delimiter Field

public static readonly char Delimiter;

Summary

Specifies the character that separates elements in the fully qualified name of a Type .

Description

This field is read-only.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.EmptyTypes Field

public static readonly Type[] EmptyTypes;

Summary

Returns an empty array of type Type .

Description

This field is read-only.

The empty Type array returned by this field is used to specify that lookup methods in the Type class, such as System.Type.GetMethod(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Reflection.CallingConventions,System.Type[],System.Reflection.ParameterModifier[]) and System.Type.GetConstructor(System.Reflection.BindingFlags,System.Reflection.Binder,System.Reflection.CallingConventions,System.Type[],System.Reflection.ParameterModifier[]), search for members that do not take parameters. [Note: For example, to locate the public instance constructor that takes no parameters, invoke System.Type.GetConstructor(System.Reflection.BindingFlags,System.Reflection.Binder,System.Reflection.CallingConventions,System.Type[],System.Reflection.ParameterModifier[]) (System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null , System.Type.EmptyTypes, null ).]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.Missing Field

public static readonly object Missing;

Summary

Represents a missing value in the Type information.

Description

This field is read-only.

Use the Missing field for invocation through reflection to ensure that a call will be made with the default value of a parameter as specified in the metadata. [Note: If the Missing field is specified for a parameter value and there is no default value for that parameter, a ArgumentException is thrown.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.Assembly Property

public abstract Assembly Assembly { get; }

Summary

Gets the Assembly that the type is declared in.

Property Value

A Assembly instance that describes assembly containing the current type.

Description

[Behaviors: This property is read-only.]

Library

RuntimeInfrastructure

See Also

System.Type Class, System Namespace

Type.AssemblyQualifiedName Property

public abstract string AssemblyQualifiedName { get; }

Summary

Gets the fully qualified name of the type represented by the current instance including the name of the assembly from which the Type was loaded.

Property Value

A String containing the fully qualified name of the type represented by the current instance, including the name of the assembly from which the Type was loaded.

Description

[Behaviors: This property is read-only.

Compilers emit the simple name of a nested class, and reflection constructs a mangled name when queried, in accordance with the following conventions.

DelimiterMeaning
Backslash (\)Escape character.
Comma (,)Precedes the Assembly name.
Plus sign (+)Precedes a nested class.
Period (.)Denotes namespace identifiers.
[Note: For example, the fully qualified name for a class might look like this:

TopNamespace.SubNameSpace.ContainingClass+NestedClass,MyAssembly

If the namespace were TopNamespace.Sub+Namespace, then the string would have to precede the plus sign (+) with an escape character (\) to prevent it from being interpreted as a nesting separator. Reflection emits this string as follows:

TopNamespace.Sub\+Namespace.ContainingClass+NestedClass,MyAssembly

A "++" becomes "\+\+", and a "\" becomes "\\".

]

Type names are permitted to include trailing characters that denote additional information about the type, such as whether the type is a reference type, a pointer type or an array type. To retrieve the type name without these trailing characters, use t.GetElementType().ToString(), where t is the type.

Spaces are significant in all type name components except the assembly name. In the assembly name, spaces before the ',' separator are significant, but spaces after the ',' separator are ignored.

]

[Usage: The name returned by this method can be persisted and later used to load the Type. To search for and load a Type, use System.Type.GetType(System.String,System.Boolean,System.Boolean) either with the type name only or with the assembly qualified type name. System.Type.GetType(System.String,System.Boolean,System.Boolean) with the type name only will look for the Type in the caller's assembly and then in the System assembly. System.Type.GetType(System.String,System.Boolean,System.Boolean) with the assembly qualified type name will look for the Type in any assembly.

]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.Attributes Property

public TypeAttributes Attributes { get; }

Summary

Gets the attributes associated with the type represented by the current instance.

Property Value

A TypeAttributes object representing the attribute set of the Type.

Description

This property is read-only.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.BaseType Property

public abstract Type BaseType { get; }

Summary

Gets the base Type of the current Type .

Property Value

A Type object representing the type from which the current Type directly inherits, or null if the current Type represents the Object class.

Description

[Behaviors: This property is read-only.]

Example

The following example demonstrates using the System.Type.BaseType property.

using System;
class TestType {
 public static void Main() {
 Type t = typeof(int);
 Console.WriteLine("{0} inherits from {1}", t,t.BaseType);
 }
}
The output is

System.Int32 inherits from System.ValueType

See Also

System.Type Class, System Namespace

Type.DeclaringType Property

public override Type DeclaringType { get; }

Summary

Gets the type that declares the type represented by the current instance.

Property Value

The Type object for the class that declares the type represented by the current instance. If the type is a nested type, this property returns the enclosing type; otherwise, returns the current instance.

Description

[Note: This property overrides System.Reflection.MemberInfo.DeclaringType.]

Example

The following example demonstrates the System.Type.DeclaringType property.

using System;
using System.Reflection;

public abstract class DeclaringTypeTest{
   public abstract class MyClassA {
      public abstract int m(); 
   }
   public abstract class MyClassB : MyClassA {
   }
   public static void Main() { 
      Console.WriteLine("Declaring type of m is {0}",
         typeof(MyClassB).GetMethod("m").DeclaringType);
   }
}
   
The output is

Declaring type of m is DeclaringTypeTest+MyClassA

Library

Reflection

See Also

System.Type Class, System Namespace

Type.DefaultBinder Property

public static Binder DefaultBinder { get; }

Summary

Gets the default binder used by the system.

Property Value

The default Binder used by the system.

Description

This property is read-only.

Reflection models the accessibility rules of the common type system. For example, if the caller is in the same assembly, the caller does not need special permissions for internal members. Otherwise, the caller needs ReflectionPermission . This is consistent with lookup of members that are protected, private, and so on.

[Note: The general principle is that System.Reflection.Binder.ChangeType(System.Object,System.Type,System.Globalization.CultureInfo) typically performs only widening coercions, which never lose data. An example of a widening coercion is coercing a value that is a 32-bit signed integer to a value that is a 64-bit signed integer. This is distinguished from a narrowing coercion, which may lose data. An example of a narrowing coercion is coercing a 64-bit signed integer to a 32-bit signed integer. ]

The following table lists the coercions performed by the default binder's implementation of ChangeType .

Source TypeTarget Type
Any typeIts base type.
Any typeThe interface it implements.
CharUnt16, UInt32, Int32, UInt64, Int64, Single, Double
ByteChar, Unt16, Int16, UInt32, Int32, UInt64, Int64, Single, Double
SByteInt16, Int32, Int64, Single, Double
UInt16UInt32, Int32, UInt64, Int64, Single, Double
Int16Int32, Int64, Single, Double
UInt32UInt64, Int64, Single, Double
Int32Int64, Single, Double
UInt64Single, Double
Int64Single, Double
SingleDouble
Non-referenceBy-reference.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.FullName Property

public abstract string FullName { get; }

Summary

Gets the fully qualified name of the type represented by the current instance.

Property Value

A String containing the fully qualified name of the Type.

Description

[Note: For example, the fully qualified name of the C# string type is "System.String".]

[Behaviors: This property is read-only.]

Example

The following example demonstrates using the System.Type.FullName property.

using System;
class TestType {
 public static void Main() {
 Type t = typeof(Array);
 Console.WriteLine("Full name of Array type is {0}",t.FullName);
 }
}
The output is

Full name of Array type is System.Array

See Also

System.Type Class, System Namespace

Type.HasElementType Property

public bool HasElementType { get; }

Summary

Gets a Boolean value indicating whether the type represented by the current instance encompasses or refers to another type; that is, whether the current Type is an array, a pointer, or is passed by reference.

Property Value

true if the Type is an array, a pointer, or is passed by reference; otherwise, false .

Description

This property is read-only.

[Note: For example, System.Type.GetType(System.String,System.Boolean,System.Boolean)("Int32 []").HasElementType returns true , but System.Type.GetType(System.String,System.Boolean,System.Boolean)("Int32 ").HasElementType returns false . System.Type.HasElementType also returns true for "Int32*" and "Int32&".]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsAbstract Property

public bool IsAbstract { get; }

Summary

Gets a Boolean value indicating whether the type represented by the current instance is abstract and is required to be overridden.

Property Value

true if the Type is abstract; otherwise, false .

Description

This property is read-only.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsArray Property

public bool IsArray { get; }

Summary

Gets a Boolean value that indicates whether the current Type represents an array.

Property Value

true if the current Type represents an array; otherwise false .

Description

This property is read-only.

This property returns true for an array of objects, but not for the Array type itself, which is a class.

Example

The following example demonstrates using the System.Type.IsArray property.

using System;
class TestType {
 public static void Main() {
 int [] array = {1,2,3,4};
 Type at = typeof(Array);
 Type t = array.GetType();
 Console.WriteLine("Type is {0}. IsArray? {1}", at, at.IsArray);
 Console.WriteLine("Type is {0}. IsArray? {1}", t, t.IsArray);
 }
}
The output is

Type is System.Array. IsArray? False

Type is System.Int32[]. IsArray? True

See Also

System.Type Class, System Namespace

Type.IsAutoLayout Property

public bool IsAutoLayout { get; }

Summary

Gets a Boolean value indicating whether the type layout attribute System.Reflection.TypeAttributes.AutoLayout is specified for the Type.

Property Value

true if the type layout attribute System.Reflection.TypeAttributes.AutoLayout is specified for the current Type; otherwise, false .

Description

This property is read-only.

[Note: The System.Reflection.TypeAttributes.AutoLayout attribute specifies that the system selects the layout the objects of the type. Types marked with this attribute indicate that the system will choose the appropriate way to lay out the type; any layout information that may have been specified is ignored.

]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsByRef Property

public bool IsByRef { get; }

Summary

Gets a Boolean value indicating whether the Type is passed by reference.

Property Value

true if the Type is passed by reference; otherwise, false .

Description

This property is read-only.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsClass Property

public bool IsClass { get; }

Summary

Gets a Boolean value that indicates whether the current Type represents a class.

Property Value

true if the current Type represents a class; otherwise false .

Description

This property is read-only.

Note that this property returns true for Type instances representing Enum and ValueType .

See Also

System.Type Class, System Namespace

Type.IsEnum Property

public bool IsEnum { get; }

Summary

Gets a Boolean value that indicates whether the current Type represents an enumeration.

Property Value

true if the current Type represents an enumeration; otherwise false .

Description

This property is read-only.

This property returns true for an enumeration, but not for the Enum type itself, which is a class.

Example

The following example demonstrates using the System.Type.IsEnum property.

using System;
public enum Color {
Red, Blue, Green
}
class TestType {
 public static void Main() {
 Type colorType = typeof(Color);
 Type enumType = typeof(Enum);
 Console.WriteLine("Color is enum ? {0}", colorType.IsEnum);
 Console.WriteLine("Color is valueType? {0}", colorType.IsValueType);
 Console.WriteLine("Enum is enum Type? {0}", enumType.IsEnum);
 Console.WriteLine("Enum is value? {0}", enumType.IsValueType);
 }
}
The output is

Color is enum ? True

Color is valueType? True

Enum is enum Type? False

Enum is value? False

See Also

System.Type Class, System Namespace

Type.IsExplicitLayout Property

public bool IsExplicitLayout { get; }

Summary

Gets a Boolean value indicating whether the type layout attribute System.Reflection.TypeAttributes.ExplicitLayout is specified for the Type.

Property Value

true if the type layout attribute System.Reflection.TypeAttributes.ExplicitLayout is specified for the current Type; otherwise, false .

Description

This property is read-only.

[Note: Types marked with the System.Reflection.TypeAttributes.ExplicitLayout attribute cause the system to ignore field sequence and to use the explicit layout rules provided, in the form of field offsets, overall class size and alignment.

]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsImport Property

public bool IsImport { get; }

Summary

Gets a Boolean value indicating whether the Type was imported from another class.

Property Value

true if the Type was imported from another class; otherwise, false .

Description

This property is read-only.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsInterface Property

public bool IsInterface { get; }

Summary

Gets a Boolean value that indicates whether the current Type represents an interface.

Property Value

true if the current Type represents an interface; otherwise false .

Description

This property is read-only.

See Also

System.Type Class, System Namespace

Type.IsLayoutSequential Property

public bool IsLayoutSequential { get; }

Summary

Gets a Boolean value indicating whether the type layout attribute System.Reflection.TypeAttributes.SequentialLayout is specified for the Type.

Property Value

true if the type layout attribute System.Reflection.TypeAttributes.SequentialLayout is specified for the current Type; otherwise, false .

Description

This property is read-only.

[Note: The System.Reflection.TypeAttributes.SequentialLayout attribute is used to indicate that the system is to preserve field order as emitted, but otherwise the specific offsets are calculated based on the type of the field; these may be shifted by explicit offset, padding, or alignment information.

]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsMarshalByRef Property

public bool IsMarshalByRef { get; }

Summary

Gets a Boolean value indicating whether the current type is marshaled by reference.

Property Value

true if the Type is marshaled by reference; otherwise, false .

Description

This property is read-only.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsNestedAssembly Property

public bool IsNestedAssembly { get; }

Summary

Gets a Boolean value indicating whether the current Type is nested and visible only within its own assembly.

Property Value

true if the Type is nested and visible only within its own assembly; otherwise, false .

Description

This property is read-only.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsNestedFamANDAssem Property

public bool IsNestedFamANDAssem { get; }

Summary

Gets a Boolean value indicating whether the current Type is nested and visible only to classes that belong to both its own family and its own assembly.

Property Value

true if the Type is nested and visible only to classes that belong to both its own family and its own assembly; otherwise, false .

Description

This property is read-only.

A Type object's family is defined as all objects of the exact same Type and of its subclasses.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsNestedFamORAssem Property

public bool IsNestedFamORAssem { get; }

Summary

Gets a Boolean value indicating whether the current Type is nested and visible only to classes that belong to either its own family or to its own assembly.

Property Value

true if the Type is nested and visible only to classes that belong to its own family or to its own assembly; otherwise, false .

Description

This property is read-only.

A Type object's family is defined as all objects of the exact same Type and of its subclasses.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsNestedFamily Property

public bool IsNestedFamily { get; }

Summary

Gets a Boolean value indicating whether the current Type is nested and visible only within its own family.

Property Value

true if the Type is nested and visible only within its own family; otherwise, false .

Description

This property is read-only.

A Type object's family is defined as all objects of the exact same Type and of its subclasses.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsNestedPrivate Property

public bool IsNestedPrivate { get; }

Summary

Gets a Boolean value indicating whether the current Type is nested and declared private.

Property Value

true if the Type is nested and declared private; otherwise, false .

Description

This property is read-only.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsNestedPublic Property

public bool IsNestedPublic { get; }

Summary

Gets a Boolean value indicating whether the current Type is a public nested class.

Property Value

true if the class is nested and declared public; otherwise, false .

Description

This property is read-only.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsNotPublic Property

public bool IsNotPublic { get; }

Summary

Gets a Boolean value indicating whether the top-level Type is not declared public.

Property Value

true if the top-level Type is not declared public; otherwise, false .

Description

This property is read-only.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsPointer Property

public bool IsPointer { get; }

Summary

Gets a Boolean value that indicates whether the current Type represents a pointer.

Property Value

This property is read-only.

true if the current Type represents a pointer; otherwise false .

Description

This property is read-only.

See Also

System.Type Class, System Namespace

Type.IsPrimitive Property

public bool IsPrimitive { get; }

Summary

Gets a Boolean value indicating whether the current Type is one of the primitive types.

Property Value

true if the Type is one of the primitive types; otherwise, false .

Description

This property is read-only.

The primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Char, Double, and Single.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsPublic Property

public bool IsPublic { get; }

Summary

Gets a Boolean value indicating whether the top-level Type is declared public.

Property Value

true if the top-level Type is declared public; otherwise, false .

Description

This property is read-only.

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsSealed Property

public bool IsSealed { get; }

Summary

Gets a Boolean value indicating whether the current Type is declared sealed.

Property Value

true if the Type is declared sealed; otherwise, false .

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsSpecialName Property

public bool IsSpecialName { get; }

Summary

Gets a Boolean value indicating whether the current Type has a name that requires special handling.

Property Value

true if the Type has a name that requires special handling; otherwise, false .

Description

This property is read-only.

[Note: Names that begin with or contain an underscore character (_) are examples of type names that might require special treatment by some tools. ]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.IsValueType Property

public bool IsValueType { get; }

Summary

Gets a Boolean value that indicates whether the current Type represents a value type.

Property Value

true if the current Type represents a value type (structure); otherwise false .

Description

This property is read-only.

This property returns true for enumerations, but not for the Enum type itself, which is a class. [Note: For an example that demonstrates this behavior, see System.Type.IsEnum .]

See Also

System.Type Class, System Namespace

Type.Module Property

public abstract Module Module { get; }

Summary

Gets the module in which the current Type is defined.

Property Value

A Module that reflects the module in which the current Type is defined.

Description

[Behaviors: This property is read-only.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.Namespace Property

public abstract string Namespace { get; }

Summary

Gets the namespace of the Type.

Property Value

A String containing the namespace of the current Type.

Description

[Note: A namespace is a logical design-time naming convenience, used mainly to define scope in an application and organize classes and other types in a hierarchical structure. From the viewpoint of the system, there are no namespaces.]

[Behaviors: This property is read-only.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.ReflectedType Property

public override Type ReflectedType { get; }

Summary

Gets the type that was used to obtain the current instance.

Property Value

The Type object through which the current instance was obtained.

Description

This property is read-only.

[Note: This property overrides System.Reflection.MemberInfo.ReflectedType.]

Example

The following example demonstrates the System.Type.ReflectedType property. Although the method m is declared in MyClassA , its reflected type is obtained from MyClassB .

using System;
using System.Reflection;
public abstract class ReflectedTypeTest {
    public abstract class MyClassA {
        public abstract int m();
    }
    public abstract class MyClassB : MyClassA {
    }
    public static void Main(string[] args) {
        Console.WriteLine("Reflected type of m is {0}",
            typeof(MyClassB).GetMethod("m").ReflectedType);
    }
}
The output is

Reflected type of m is ReflectedTypeTest+MyClassB

Library

Reflection

See Also

System.Type Class, System Namespace

Type.TypeHandle Property

public abstract RuntimeTypeHandle TypeHandle { get; }

Summary

Gets the handle for the current Type.

Property Value

The RuntimeTypeHandle for the current Type.

Description

This property is read-only.

The RuntimeTypeHandle encapsulates a pointer to an internal data structure that represents the type. This handle is unique during the process lifetime. The handle is valid only in the application domain in which it was obtained.

Library

RuntimeInfrastructure

See Also

System.Type Class, System Namespace

Type.TypeInitializer Property

public ConstructorInfo TypeInitializer { get; }

Summary

Gets the initializer for the type represented by the current instance.

Property Value

A ConstructorInfo containing the name of the static constructor for the type represented by the current instance

Description

This property is read-only.

[Note: Type initializers are available through System.Type.GetMember(System.String), System.Type.GetMembers, System.Type.FindMembers(System.Reflection.MemberTypes,System.Reflection.BindingFlags,System.Reflection.MemberFilter,System.Object), and System.Type.GetConstructors.]

Library

Reflection

See Also

System.Type Class, System Namespace

Type.UnderlyingSystemType Property

public abstract Type UnderlyingSystemType { get; }

Summary

Returns the system-supplied type that represents the current type.

Property Value

The underlying system type for the Type.

Description

This property is read-only.

[Behaviors: As described above.]

Library

Reflection

See Also

System.Type Class, System Namespace