public abstract class Type : Object
Object
MemberInfo (excluded)
Type
mscorlib
BCL
Provides information about a type.
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[]).
- Classes
- Value types
- Arrays
- Interfaces
- Pointers
- Enumerations
Member Type Static Constructor No Field No Event Not applicable Method No Nested Type No Property Not 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.
]
System Namespace
Type Constructors
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
protected Type();
Constructs a new instance of the Type class.
Reflection
System.Type Class, System Namespace
public bool Equals(Type o);
Determines if the underlying system type of the current Type is the same as the underlying system type of the specified Type.
- o
- The Type whose underlying system type is to be compared with the underlying system type of the current Type.
true
if the underlying system type of o is the same as the underlying system type of the current Type; otherwise,false
.
Reflection
System.Type Class, System Namespace
public virtual int GetArrayRank();
Returns the number of dimensions in the current Type.
A Int32 containing the number of dimensions in the current Type.
Exception Type Condition ArgumentException The current Type is not an array.
System.Type Class, System Namespace
protected abstract TypeAttributes GetAttributeFlagsImpl();
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.
A TypeAttributes value that signifies the attributes of the type represented by the current instance.
[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.]
Reflection
System.Type Class, System Namespace
public ConstructorInfo GetConstructor(BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers);
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.
- 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
.
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, returnsnull
. 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, returnsnull
.
Exception Type Condition ArgumentNullException types is null
, or at least one of the elements in types isnull
.
ArgumentException types has more than one dimension.
The following BindingFlags are used to define which constructors to include in the search:
[Note: For more information, see BindingFlags.]
- Specify either System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static to get a return value other than
null
.- Specify System.Reflection.BindingFlags.Public to include public constructors in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public constructors (that is, private and protected constructors) in the search.
Reflection
System.Type Class, System Namespace
public ConstructorInfo GetConstructor(Type[] types);
Returns a public instance constructor defined in the type represented by the current instance. The parameters of the constructor match the specified argument types.
- 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.
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, returnsnull
.
Exception Type Condition ArgumentNullException types is null
, or at least one of the elements in types isnull
.
ArgumentException types has more than one dimension.
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
).
Reflection
System.Type Class, System Namespace
public abstract ConstructorInfo[] GetConstructors(BindingFlags bindingAttr);
Returns an array of constructors defined in the type represented by the current instance, under the specified binding constraints.
- bindingAttr
- A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns
null
.
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, returnsnull
.
The following BindingFlags are used to define which constructors to include in the search:
[Note: For more information, see BindingFlags.]
- Specify either System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static to get a return value other than
null
.- Specify System.Reflection.BindingFlags.Public to include public constructors in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public constructors (that is, private and protected constructors) in the search.
[Behaviors: As described above.]
Reflection
System.Type Class, System Namespace
public ConstructorInfo[] GetConstructors();
Returns an array of the public constructors defined in the type represented by the current instance.
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.
This version of System.Type.GetConstructors is equivalent to System.Type.GetConstructors(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).
Reflection
System.Type Class, System Namespace
public virtual MemberInfo[] GetDefaultMembers();
Returns an array of MemberInfo objects that reflect the default members defined in the type represented by the current instance.
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.
[Behaviors: The members returned by this method have the DefaultMemberAttribute attribute.]
Reflection
System.Type Class, System Namespace
public abstract Type GetElementType();
Returns the element type of the current Type .
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, returnsnull
.
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
System.Type Class, System Namespace
public abstract EventInfo GetEvent(string name, BindingFlags bindingAttr);
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.
- 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.
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, returnsnull
. If the event is not public, the current instance represents a type from a loaded assembly, and the caller does not have sufficient permission, returnsnull
.
Exception Type Condition ArgumentNullException name is null
.
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:
- Specify either System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static to get a return value other than
null
.- Specify System.Reflection.BindingFlags.Public to include public events in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public events(that is, private and protected events) in the search.
- Specify System.Reflection.BindingFlags.FlattenHierarchy to include to include static members declared in ancestors in the search.
[Note: For more information, see BindingFlags.]
- System.Reflection.BindingFlags.DeclaredOnly to search only the events declared on the type, not events that were simply inherited.
[Behaviors: As described above.]
Reflection
System.Type Class, System Namespace
public EventInfo GetEvent(string name);
Returns a EventInfo object reflecting the public event that has the specified name and is defined in the type represented by the current instance.
- name
- A String containing the name of the public event to be returned.
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
.
Exception Type Condition ArgumentNullException name is null
.
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.
Reflection
System.Type Class, System Namespace
public abstract EventInfo[] GetEvents(BindingFlags bindingAttr);
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.
- bindingAttr
- A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns null.
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.
The following BindingFlags are used to define which events to include in the search:
[Note: For more information, see BindingFlags.]
- Specify either System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static to get a return value other than
null
.- Specify System.Reflection.BindingFlags.Public to include public events in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public events (that is, private and protected events) in the search.
[Behaviors: As described above.]
Reflection
System.Type Class, System Namespace
public virtual EventInfo[] GetEvents();
Returns an array of EventInfo objects that reflect the public events defined in the type represented by the current instance.
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.
[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).]
Reflection
System.Type Class, System Namespace
public abstract FieldInfo GetField(string name, BindingFlags bindingAttr);
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.
- 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
.
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, returnsnull
. If the field is not public, the current type is from a loaded assembly, and the caller does not have sufficient permission, returnsnull
.
Exception Type Condition ArgumentNullException name is null
.
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:
- Specify either System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static to get a return value other than
null
.- Specify System.Reflection.BindingFlags.Public to include public fields in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public fields (that is, private and protected fields) in the search.
- Specify System.Reflection.BindingFlags.FlattenHierarchy to include static members declared in ancestors in the search.
[Note: For more information, see BindingFlags.]
- System.Reflection.BindingFlags.DeclaredOnly to search only the fields declared in the type, not fields that were simply inherited.
- System.Reflection.BindingFlags.IgnoreCase to ignore the case of name.
[Behaviors: As described above.]
Reflection
System.Type Class, System Namespace
public FieldInfo GetField(string name);
Returns a FieldInfo object reflecting the field that has the specified name and is defined in the type represented by the current instance.
- name
- A String containing the name of the field to be returned.
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, returnsnull
.
Exception Type Condition ArgumentNullException name is null
.
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 ).
Reflection
System.Type Class, System Namespace
public abstract FieldInfo[] GetFields(BindingFlags bindingAttr);
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.
- bindingAttr
- A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns
null
.
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.
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:
- Specify either System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static in order to get a return value other than
null
.- Specify System.Reflection.BindingFlags.Public to include public fields in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public fields (that is, private and protected fields) in the search.
- Specify System.Reflection.BindingFlags.FlattenHierarchy to include static members declared in ancestors in the search.
[Note: For more information, see BindingFlags.]
- System.Reflection.BindingFlags.DeclaredOnly to search only the fields declared in the type, not fields that were simply inherited.
[Behaviors: As described above.]
Reflection
System.Type Class, System Namespace
public FieldInfo[] GetFields();
Returns an array of FieldInfo objects that reflect the public fields defined in the type represented by the current instance.
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.
This version of System.Type.GetFields is equivalent to System.Type.GetFields( System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public ).
Reflection
System.Type Class, System Namespace
public override int GetHashCode();
Generates a hash code for the current instance.
A Int32 containing the hash code for this instance.
The algorithm used to generate the hash code is unspecified.[Note: This method overrides System.Object.GetHashCode .]
System.Type Class, System Namespace
public abstract Type GetInterface(string name, bool ignoreCase);
Returns the specified interface, specifying whether to do a case-sensitive search.
- 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, andfalse
performs a case-sensitive search.
A Type object representing the interface with the specified name, implemented or inherited by the type represented by the instance, if found; otherwise,null
.
Exception Type Condition ArgumentNullException name is null
.
Reflection
System.Type Class, System Namespace
public Type GetInterface(string name);
Searches for the interface with the specified name.
- name
- A String containing the name of the interface to get.
A Type object representing the interface with the specified name, implemented or inherited by the current Type, if found; otherwise,null
.
Exception Type Condition ArgumentNullException name is null
.
The search for name is case-sensitive.
Reflection
System.Type Class, System Namespace
public abstract Type[] GetInterfaces();
Returns all interfaces implemented or inherited by the type represented by the current instance.
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.
Reflection
System.Type Class, System Namespace
public virtual MemberInfo[] GetMember(string name, BindingFlags bindingAttr);
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.
- 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
.
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, returnsnull
.
Exception Type Condition ArgumentNullException name is null
.
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:
- Specify either System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static to get a return value other than
null
.- Specify System.Reflection.BindingFlags.Public to include public members in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public members (that is, private and protected members) in the search.
- Specify System.Reflection.BindingFlags.FlattenHierarchy to include static members declared in ancestors in the search.
[Note: For more information, see BindingFlags.]
- System.Reflection.BindingFlags.DeclaredOnly to search only the members declared in the type, not members that were simply inherited.
- System.Reflection.BindingFlags.IgnoreCase to ignore the case of name.
[Behaviors: As described above.]
Reflection
System.Type Class, System Namespace
public MemberInfo[] GetMember(string name);
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.
- name
- A String containing the name of the members to be returned.
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.
Exception Type Condition ArgumentNullException name is null
.
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.
Reflection
System.Type Class, System Namespace
public abstract MemberInfo[] GetMembers(BindingFlags bindingAttr);
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.
- bindingAttr
- A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns
null
.
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.
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:
- Specify either System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static to get a return value other than
null
.- Specify System.Reflection.BindingFlags.Public to include public members in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public members (that is, private and protected members) in the search.
- Specify System.Reflection.BindingFlags.FlattenHierarchy to include static members declared in ancestors in the search.
[Note: For more information, see BindingFlags.]
- System.Reflection.BindingFlags.DeclaredOnly to search only the members declared in the type, not members that were simply inherited.
[Behaviors: As described above.]
Reflection
System.Type Class, System Namespace
public MemberInfo[] GetMembers();
Returns an array of MemberInfo objects that reflect the public members defined in the type represented by the current instance.
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.
This version of System.Type.GetMembers is equivalent to System.Type.GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Instance).
Reflection
System.Type Class, System Namespace
public MethodInfo GetMethod(string name, BindingFlags bindingAttr);
Returns a MethodInfo object that reflects the method that has the specified name and is defined in the type represented by the current instance.
- 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
.
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
.
Exception Type Condition AmbiguousMatchException More than one method matching the specified criteria was found. ArgumentNullException name is null
.
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:
- Specify either System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static to get a return value other than
null
.- Specify System.Reflection.BindingFlags.Public to include public members in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public members (that is, private and protected members) in the search.
- Specify System.Reflection.BindingFlags.FlattenHierarchy to include static members declared in ancestors in the search.
[Note: For more information, see BindingFlags.]
- System.Reflection.BindingFlags.DeclaredOnly to search only the members declared in the type, not members that were simply inherited.
- System.Reflection.BindingFlags.IgnoreCase to ignore the case of name.
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
).
Reflection
System.Type Class, System Namespace
public MethodInfo GetMethod(string name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers);
Returns a MethodInfo object that reflects the method that matches the specified criteria and is defined in the type represented by the current instance.
- 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
.
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, returnsnull
. 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, returnsnull
.
Exception Type Condition AmbiguousMatchException More than one method matching the specified criteria was found. ArgumentNullException name or types is null
.-or-
At least one of the elements in types is
null
.
ArgumentException types has more than one dimension.
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:
- Specify either System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static to get a return value other than
null
.- Specify System.Reflection.BindingFlags.Public to include public members in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public members (that is, private and protected members) in the search.
- Specify System.Reflection.BindingFlags.FlattenHierarchy to include static members declared in ancestors in the search.
[Note: For more information, see BindingFlags.]
- System.Reflection.BindingFlags.DeclaredOnly to search only the members declared in the type, not members that were simply inherited.
- System.Reflection.BindingFlags.IgnoreCase to ignore the case of name.
Reflection
System.Type Class, System Namespace
public MethodInfo GetMethod(string name, Type[] types, ParameterModifier[] modifiers);
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.
- 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
.
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
.
Exception Type Condition AmbiguousMatchException More than one method matching the specified criteria was found. ArgumentNullException name or types is null
.-or-
At least one of the elements in types is
null
.
ArgumentException types has more than one dimension.
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).
Reflection
System.Type Class, System Namespace
public MethodInfo GetMethod(string name, Type[] types);
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.
- 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.
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, returnsnull
.
Exception Type Condition AmbiguousMatchException More than one method matching the specified criteria was found. ArgumentNullException name or types is null
.-or-
At least one of the elements in types is
null
.
ArgumentException types has more than one dimension.
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
).
Reflection
System.Type Class, System Namespace
public MethodInfo GetMethod(string name);
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.
- name
- A String containing the name of the public method to be returned.
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
.
Exception Type Condition AmbiguousMatchException More than one method matching the specified criteria was found. ArgumentNullException name is null
.
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
).
Reflection
System.Type Class, System Namespace
public abstract MethodInfo[] GetMethods(BindingFlags bindingAttr);
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.
- bindingAttr
- A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns
null
.
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.
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:
- Specify either System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static to get a return value other than
null
.- Specify System.Reflection.BindingFlags.Public to include public members in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public members (that is, private and protected members) in the search.
- Specify System.Reflection.BindingFlags.FlattenHierarchy to include static members declared in ancestors in the search.
[Note: For more information, see BindingFlags.]
- System.Reflection.BindingFlags.DeclaredOnly to search only the members declared in the type, not members that were simply inherited.
[Behaviors: As described above.]
Reflection
System.Type Class, System Namespace
public MethodInfo[] GetMethods();
Returns the public methods defined in the type represented by the current instance.
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.
This version of System.Type.GetMethods is equivalent to System.Type.GetMethods( System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public ).
Reflection
System.Type Class, System Namespace
public abstract Type GetNestedType(string name, BindingFlags bindingAttr);
Returns a nested types defined in the type represented by the current instance that match the specified binding constraints.
- 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
.
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, returnsnull
.
Exception Type Condition ArgumentNullException name is null
.
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:
- Specify either System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static to get a return value other than
null
.- Specify System.Reflection.BindingFlags.Public to include public members in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public members (that is, private and protected members) in the search.
- Specify System.Reflection.BindingFlags.FlattenHierarchy to include static members declared in ancestors in the search.
[Note: For more information, see BindingFlags.]
- System.Reflection.BindingFlags.DeclaredOnly to search only the members declared in the type, not members that were simply inherited.
- System.Reflection.BindingFlags.IgnoreCase to ignore the case of name.
Reflection
System.Type Class, System Namespace
public Type GetNestedType(string name);
Returns the public nested type defined in the type represented by the current instance
- 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"). ]
A Type object representing the public nested type with the specified name, if found; otherwise,null
.
Exception Type Condition ArgumentNullException name is null
.
The search for name is case-sensitive.This version of System.Type.GetNestedTypes is equivalent to System.Type.GetNestedTypes(name, System.Reflection.BindingFlags.Public).
Reflection
System.Type Class, System Namespace
public abstract Type[] GetNestedTypes(BindingFlags bindingAttr);
Returns an array containing the nested types defined in the type represented by the current instance that match the specified binding constraints.
- bindingAttr
- A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns
null
.
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.
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:
- Specify System.Reflection.BindingFlags.Public to include public members in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public members (that is, private and protected members) in the search.
- Specify System.Reflection.BindingFlags.FlattenHierarchy to include static members declared in ancestors in the search.
[Note: For more information, see BindingFlags.]
- System.Reflection.BindingFlags.DeclaredOnly to search only the members declared in the type, not members that were simply inherited.
Reflection
System.Type Class, System Namespace
public Type[] GetNestedTypes();
Returns all the public types nested within the current Type.
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.
This version of System.Type.GetNestedTypes is equivalent to System.Type.GetNestedTypes(System.Reflection.BindingFlags.Public).
Reflection
System.Type Class, System Namespace
public abstract PropertyInfo[] GetProperties(BindingFlags bindingAttr);
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.
- bindingAttr
- A bitwise combination of BindingFlags values that control the binding process. If zero is specified, this method returns
null
.
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.
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:
- Specify either System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static to get a return value other than
null
.- Specify System.Reflection.BindingFlags.Public to include public members in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public members (that is, private and protected members) in the search.
- Specify System.Reflection.BindingFlags.FlattenHierarchy to include static members declared in ancestors in the search.
[Note: For more information, see BindingFlags.]
- System.Reflection.BindingFlags.DeclaredOnly to search only the members declared in the type, not members that were simply inherited.
[Behaviors: A property is considered by reflection to be
public
if it has at least one accessor that ispublic
. Otherwise, the property is notpublic
.]
Reflection
System.Type Class, System Namespace
public PropertyInfo[] GetProperties();
Returns an array of PropertyInfo objects that reflect the public properties defined in the type represented by the current instance.
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.
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 ispublic
. Otherwise, the property is considered to be notpublic
.
Reflection
System.Type Class, System Namespace
public PropertyInfo GetProperty(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers);
Returns a PropertyInfo object that reflects the property defined in the type represented by the current instance that matches the specified search criteria .
- 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
.
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, returnsnull
. 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, returnsnull
.
Exception Type Condition AmbiguousMatchException More than one property matching the specified criteria was found. ArgumentNullException name or types is null
, or at least one of the elements in types isnull
.
ArgumentException types has more than one dimension.
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:
- Specify either System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static to get a return value other than
null
.- Specify System.Reflection.BindingFlags.Public to include public members in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public members (that is, private and protected members) in the search.
- Specify System.Reflection.BindingFlags.FlattenHierarchy to include static members declared in ancestors in the search.
[Note: For more information, see BindingFlags.]
- System.Reflection.BindingFlags.DeclaredOnly to search only the members declared in the type, not members that were simply inherited.
- System.Reflection.BindingFlags.IgnoreCase to ignore the case of name.
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.
Reflection
System.Type Class, System Namespace
public PropertyInfo GetProperty(string name, BindingFlags bindingAttr);
Returns a PropertyInfo object that reflects the property defined in the type represented by the current instance that matches the specified search criteria.
- 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
.
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, returnsnull
. 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, returnsnull
.
Exception Type Condition AmbiguousMatchException More than one property matching the specified criteria was found. ArgumentNullException name is null
.
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:
- Specify either System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static to get a return value other than
null
.- Specify System.Reflection.BindingFlags.Public to include public members in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public members (that is, private and protected members) in the search.
- Specify System.Reflection.BindingFlags.FlattenHierarchy to include static members declared in ancestors in the search.
[Note: For more information, see BindingFlags.]
- System.Reflection.BindingFlags.DeclaredOnly to search only the members declared in the type, not members that were simply inherited.
- System.Reflection.BindingFlags.IgnoreCase to ignore the case of name.
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.
Reflection
System.Type Class, System Namespace
public PropertyInfo GetProperty(string name, Type returnType, Type[] types);
Returns a PropertyInfo object that reflects the public property defined in the type represented by the current instance that matches the specified search criteria.
- 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.
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, returnsnull
.
Exception Type Condition AmbiguousMatchException More than one property matching the specified criteria was found. ArgumentNullException name or types is null
, or at least one of the elements in types isnull
.
ArgumentException types has more than one dimension.
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.
Reflection
System.Type Class, System Namespace
public PropertyInfo GetProperty(string name, Type[] types);
Returns a PropertyInfo object that reflects the public property defined in the type represented by the current instance that matches the specified search criteria.
- 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.
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, returnsnull
.
Exception Type Condition AmbiguousMatchException More than one property matching the specified criteria was found. ArgumentNullException name or types is null
, or at least one of the elements in types isnull
.
ArgumentException types has more than one dimension.
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.
Reflection
System.Type Class, System Namespace
public PropertyInfo GetProperty(string name, Type returnType);
Returns a PropertyInfo object that reflects the public property defined in the type represented by the current instance that matches the specified search criteria.
- 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.
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, returnsnull
.
Exception Type Condition AmbiguousMatchException More than one property matching the specified criteria was found. ArgumentNullException name is null
.
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.
Reflection
System.Type Class, System Namespace
public PropertyInfo GetProperty(string name);
Returns a PropertyInfo object that reflects the public property defined in the type represented by the current instance that has the specified name.
- name
- A String containing the name of the property to be returned.
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, returnsnull
.
Exception Type Condition AmbiguousMatchException More than one property matching the specified criteria was found. ArgumentNullException name is null
.
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.
Reflection
System.Type Class, System Namespace
protected abstract PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers);
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.
- 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
.
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, returnsnull
.
Exception Type Condition AmbiguousMatchException More than one property matching the specified criteria was found. ArgumentNullException name or types is null
, or at least one of the elements in types isnull
.
ArgumentException types has more than one dimension.
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:
- Specify either System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static to get a return value other than
null
.- Specify System.Reflection.BindingFlags.Public to include public members in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public members (that is, private and protected members) in the search.
- Specify System.Reflection.BindingFlags.FlattenHierarchy to include static members declared in ancestors in the search.
[Note: For more information, see BindingFlags.]
- System.Reflection.BindingFlags.DeclaredOnly to search only the members declared in the type, not members that were simply inherited.
- System.Reflection.BindingFlags.IgnoreCase to ignore the case of name.
[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. ]
Reflection
System.Type Class, System Namespace
public static Type GetType(string typeName, bool throwOnError, bool ignoreCase);
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.
- 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. Specifyfalse
to ignore errors while loading the Type.
- ignoreCase
- A Boolean. Specify
true
to perform a case-insensitive search for typeName. Specifyfalse
to perform a case-sensitive search for typeName .
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 returnsnull
.
Exception Type Condition ArgumentNullException typeName is null
.TargetInvocationException A type initializer was invoked and threw an exception. TypeLoadException throwOnError is true
and an error was encountered while loading the selected Type.
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 Get Use 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 class Type.GetType("MyParentClass+MyNestedClass")
A one-dimensional array with a lower bound of 0 Type.GetType("MyArray[]")
A one-dimensional array with an unknown lower bound Type.GetType("MyArray[*]")
An n-dimensional array A comma (,) inside the brackets a total of n-1 times. For example, System.Object[,,]
represents a three-dimensionalObject
array.A two-dimensional array's array Type.GetType("MyArray[][]")
A rectangular two-dimensional array with unknown lower bounds Type.GetType("MyArray[*,*]")
orType.GetType("MyArray[,]")
Reflection
System.Type Class, System Namespace
public static Type GetType(string typeName, bool throwOnError);
Returns the Type with the specified name, optionally throwing an exception if an error occurs while loading the Type .
- 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. Specifyfalse
to ignore errors while loading the Type.
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 returnsnull
.
Exception Type Condition ArgumentNullException typeName is null
.TargetInvocationException A type initializer was invoked and threw an exception. TypeLoadException throwOnError is true
and an error was encountered while loading the Type.
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). ]
Reflection
System.Type Class, System Namespace
public static Type GetType(string typeName);
Returns the Type with the specified name.
- typeName
- A String containing the case-sensitive name of the Type to return.
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 returnsnull
.
Exception Type Condition ArgumentNullException typeName is null
.TargetInvocationException A type initializer was invoked and threw an exception.
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).]
Reflection
System.Type Class, System Namespace
public static Type[] GetTypeArray(object[] args);
Returns the types of the objects in the specified array.
- args
- An array of objects whose types are to be returned.
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 benull
.
Exception Type Condition ArgumentNullException args is null
.TargetInvocationException The type initializers were invoked and at least one threw an exception.
Reflection
System.Type Class, System Namespace
public static Type GetTypeFromHandle(RuntimeTypeHandle handle);
Gets the Type referenced by the specified type handle.
- handle
- The RuntimeTypeHandle object that refers to the desired Type.
The Type referenced by the specified RuntimeTypeHandle.
Exception Type Condition ArgumentNullException handle is null
.SecurityException The requested type is non-public and outside the current assembly, and the caller does not have the required permission. TargetInvocationException A type initializer was invoked and threw an exception.
The handles are valid only in the application domain in which they were obtained.
RuntimeInfrastructure
System.Type Class, System Namespace
public static RuntimeTypeHandle GetTypeHandle(object o);
Returns the handle for the Type of the specified object.
- o
- The object for which to get the type handle.
The RuntimeTypeHandle for the Type of the specified Object.
The handle is valid only in the application domain in which it was obtained.
RuntimeInfrastructure
System.Type Class, System Namespace
protected abstract bool HasElementTypeImpl();
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.
true
if the Type is an array, a pointer, or is passed by reference; otherwise,false
.
[Note: For example, System.Type.GetType(System.String,System.Boolean,System.Boolean) ("System.Int32[]").HasElementTypeImpl returnstrue
, but System.Type.GetType(System.String,System.Boolean,System.Boolean) ("System.Int32").HasElementTypeImpl returnsfalse
. System.Type.HasElementTypeImpl also returnstrue
for "System.Int32*" and "System.Int32&".]
Reflection
System.Type Class, System Namespace
public abstract object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters);
Invokes or accesses a member defined on the type represented by the current instance that matches the specified binding criteria.
- 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 notnull
, the order of the elements in args corresponds to the order of the parameters specified in namedParameters. Specify an empty array ornull
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. Specifynull
to have this parameter ignored.
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 .
Exception Type Condition ArgumentNullException name is null
.
ArgumentException args 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.
MissingFieldException A field or property matching the specified criteria was not found. MissingMethodException A method matching the specified criteria cannot be found. MethodAccessException The requested member is non-public and the caller does not have the required permission. TargetException The member matching the specified criteria cannot be invoked on target. TargetInvocationException The member matching the specified criteria threw an exception. AmbiguousMatchException More than one member matches the specified criteria.
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:
- Specify either System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static to get a return value other than
null
.- Specify System.Reflection.BindingFlags.Public to include public members in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public members (that is, private and protected members) in the search.
- Specify System.Reflection.BindingFlags.FlattenHierarchy to include static members declared in ancestors in the search.
[Note: For more information, see BindingFlags.]
- System.Reflection.BindingFlags.DeclaredOnly to search only the members declared in the type, not members that were simply inherited.
- System.Reflection.BindingFlags.IgnoreCase to ignore the case of name.
[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:
Action BindingFlags 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".
]
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 "".
Reflection
System.Type Class, System Namespace
public object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, CultureInfo culture);
Invokes the specified member, using the specified binding constraints and matching the specified argument list and culture.
- 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
.
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 .
Exception Type Condition ArgumentNullException name is null
.
ArgumentException args 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.
MissingFieldException A field or property matching the specified criteria was not found. MissingMethodException A method matching the specified criteria was not found. MethodAccessException The requested member is non-public and the caller does not have the required permission. TargetException The member matching the specified criteria cannot be invoked on target. TargetInvocationException The member matching the specified criteria threw an exception. AmbiguousMatchException More than one member matches the specified criteria.
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
).
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[]).
Reflection
System.Type Class, System Namespace
public object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args);
Invokes the specified member, using the specified binding constraints and matching the specified argument list.
- 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.
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 .
Exception Type Condition ArgumentNullException name is null
.
ArgumentException args 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.
MissingFieldException A field or property matching the specified criteria was not found. MissingMethodException A method matching the specified criteria cannot be found. MethodAccessException The requested member is non-public and the caller does not have the required permission. TargetException The member matching the specified criteria cannot be invoked on target. TargetInvocationException The member matching the specified criteria threw an exception. AmbiguousMatchException More than one member matches the specified criteria.
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[]).]
Reflection
System.Type Class, System Namespace
protected abstract bool IsArrayImpl();
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.
true
if the Type is an array; otherwise,false
.
An instance of the Array class is required to returnfalse
because it is an object, not an array.[Behaviors: As described above.]
Reflection
System.Type Class, System Namespace
public virtual bool IsAssignableFrom(Type c);
Determines whether an instance of the current Type can be assigned from an instance of the specified Type .
- c
- The Type to compare with the current Type .
false
if c is a null reference.
true
if one or more of the following statements are true; otherwisefalse
.
- If c and the current Type represent the same type.
- If the current Type is in the inheritance hierarchy of c.
- If the current Type is an interface and c supports that interface.
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
System.Type Class, System Namespace
protected abstract bool IsByRefImpl();
When overridden in a derived class, implements the System.Type.IsByRef property and determines whether the Type is passed by reference.
true
if the Type is passed by reference; otherwise,false
.
[Behaviors: As described above.]
Reflection
System.Type Class, System Namespace
protected abstract bool IsCOMObjectImpl();
Reserved.
false
This abstract method is required to be present for legacy implementations. Conforming implementations are permitted to throw the NotSupportedException as their implementation.
Reflection
System.Type Class, System Namespace
public virtual bool IsInstanceOfType(object o);
Determines whether the specified object is an instance of the current Type.
- o
- The object to compare with the current Type.
true
if either of the following statements is true; otherwisefalse
.
If o is a null reference, returns
- If the current Type is in the inheritance hierarchy of o.
- If the current Type is an interface and o supports that interface.
false
.
[Behaviors: As described above.]
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
System.Type Class, System Namespace
protected abstract bool IsPointerImpl();
When overridden in a derived class, implements the System.Type.IsPointer property and determines whether the Type is a pointer.
true
if the Type is a pointer; otherwise,false
.
[Behaviors: As described above.]
Reflection
System.Type Class, System Namespace
protected abstract bool IsPrimitiveImpl();
When overridden in a derived class, implements the System.Type.IsPrimitive property and determines whether the Type is one of the primitive types.
true
if the Type is one of the primitive types; otherwise,false
.
[Behaviors: This method returnstrue
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.]
Reflection
System.Type Class, System Namespace
public virtual bool IsSubclassOf(Type c);
Determines whether the current Type derives from the specified Type .
- c
- The Type to compare with the current Type.
true
if c and the current Type represent classes, and the class represented by the current Type derives from the class represented by c; otherwisefalse
. Returnsfalse
if c and the current Type represent the same class.
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
System.Type Class, System Namespace
public override string ToString();
Returns a String representation of the current Type.
Returns System.Type.FullName .
[Note: This method overrides System.Object.ToString .]
System.Type Class, System Namespace
public static readonly char Delimiter;
Specifies the character that separates elements in the fully qualified name of a Type .
This field is read-only.
Reflection
System.Type Class, System Namespace
public static readonly Type[] EmptyTypes;
Returns an empty array of type Type .
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
).]
Reflection
System.Type Class, System Namespace
public static readonly object Missing;
Represents a missing value in the Type information.
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 theMissing
field is specified for a parameter value and there is no default value for that parameter, a ArgumentException is thrown.]
Reflection
System.Type Class, System Namespace
public abstract Assembly Assembly { get; }
Gets the Assembly that the type is declared in.
A Assembly instance that describes assembly containing the current type.
[Behaviors: This property is read-only.]
RuntimeInfrastructure
System.Type Class, System Namespace
public abstract string AssemblyQualifiedName { get; }
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.
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.
[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.
[Note: For example, the fully qualified name for a class might look like this:
Delimiter Meaning Backslash (\) Escape character. Comma (,) Precedes the Assembly name. Plus sign (+) Precedes a nested class. Period (.) Denotes namespace identifiers. 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.
]
Reflection
System.Type Class, System Namespace
public TypeAttributes Attributes { get; }
Gets the attributes associated with the type represented by the current instance.
A TypeAttributes object representing the attribute set of the Type.
This property is read-only.
Reflection
System.Type Class, System Namespace
public abstract Type BaseType { get; }
Gets the base Type of the current Type .
A Type object representing the type from which the current Type directly inherits, ornull
if the current Type represents the Object class.
[Behaviors: This property is read-only.]
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
System.Type Class, System Namespace
public override Type DeclaringType { get; }
Gets the type that declares the type represented by the current instance.
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.
[Note: This property overrides System.Reflection.MemberInfo.DeclaringType.]
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
Reflection
System.Type Class, System Namespace
public static Binder DefaultBinder { get; }
Gets the default binder used by the system.
The default Binder used by the system.
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 Type Target Type Any type Its base type. Any type The interface it implements. Char Unt16, UInt32, Int32, UInt64, Int64, Single, Double Byte Char, Unt16, Int16, UInt32, Int32, UInt64, Int64, Single, Double SByte Int16, Int32, Int64, Single, Double UInt16 UInt32, Int32, UInt64, Int64, Single, Double Int16 Int32, Int64, Single, Double UInt32 UInt64, Int64, Single, Double Int32 Int64, Single, Double UInt64 Single, Double Int64 Single, Double Single Double Non-reference By-reference.
Reflection
System.Type Class, System Namespace
public abstract string FullName { get; }
Gets the fully qualified name of the type represented by the current instance.
A String containing the fully qualified name of the Type.
[Note: For example, the fully qualified name of the C# string type is "System.String".]
[Behaviors: This property is read-only.]
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
System.Type Class, System Namespace
public bool HasElementType { get; }
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.
true
if the Type is an array, a pointer, or is passed by reference; otherwise,false
.
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 returnsfalse
. System.Type.HasElementType also returnstrue
for "Int32*" and "Int32&".]
Reflection
System.Type Class, System Namespace
public bool IsAbstract { get; }
Gets a Boolean value indicating whether the type represented by the current instance is abstract and is required to be overridden.
true
if the Type is abstract; otherwise,false
.
This property is read-only.
Reflection
System.Type Class, System Namespace
public bool IsArray { get; }
Gets a Boolean value that indicates whether the current Type represents an array.
true
if the current Type represents an array; otherwisefalse
.
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.
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
System.Type Class, System Namespace
public bool IsAutoLayout { get; }
Gets a Boolean value indicating whether the type layout attribute System.Reflection.TypeAttributes.AutoLayout is specified for the Type.
true
if the type layout attribute System.Reflection.TypeAttributes.AutoLayout is specified for the current Type; otherwise,false
.
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.
]
Reflection
System.Type Class, System Namespace
public bool IsByRef { get; }
Gets a Boolean value indicating whether the Type is passed by reference.
true
if the Type is passed by reference; otherwise,false
.
This property is read-only.
Reflection
System.Type Class, System Namespace
public bool IsClass { get; }
Gets a Boolean value that indicates whether the current Type represents a class.
true
if the current Type represents a class; otherwisefalse
.
This property is read-only.Note that this property returns
true
for Type instances representing Enum and ValueType .
System.Type Class, System Namespace
public bool IsEnum { get; }
Gets a Boolean value that indicates whether the current Type represents an enumeration.
true
if the current Type represents an enumeration; otherwisefalse
.
This property is read-only.This property returns
true
for an enumeration, but not for the Enum type itself, which is a class.
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
System.Type Class, System Namespace
public bool IsExplicitLayout { get; }
Gets a Boolean value indicating whether the type layout attribute System.Reflection.TypeAttributes.ExplicitLayout is specified for the Type.
true
if the type layout attribute System.Reflection.TypeAttributes.ExplicitLayout is specified for the current Type; otherwise,false
.
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.
]
Reflection
System.Type Class, System Namespace
public bool IsImport { get; }
Gets a Boolean value indicating whether the Type was imported from another class.
true
if the Type was imported from another class; otherwise,false
.
This property is read-only.
Reflection
System.Type Class, System Namespace
public bool IsInterface { get; }
Gets a Boolean value that indicates whether the current Type represents an interface.
true
if the current Type represents an interface; otherwisefalse
.
This property is read-only.
System.Type Class, System Namespace
public bool IsLayoutSequential { get; }
Gets a Boolean value indicating whether the type layout attribute System.Reflection.TypeAttributes.SequentialLayout is specified for the Type.
true
if the type layout attribute System.Reflection.TypeAttributes.SequentialLayout is specified for the current Type; otherwise,false
.
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.
]
Reflection
System.Type Class, System Namespace
public bool IsMarshalByRef { get; }
Gets a Boolean value indicating whether the current type is marshaled by reference.
true
if the Type is marshaled by reference; otherwise,false
.
This property is read-only.
Reflection
System.Type Class, System Namespace
public bool IsNestedAssembly { get; }
Gets a Boolean value indicating whether the current Type is nested and visible only within its own assembly.
true
if the Type is nested and visible only within its own assembly; otherwise,false
.
This property is read-only.
Reflection
System.Type Class, System Namespace
public bool IsNestedFamANDAssem { get; }
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.
true
if the Type is nested and visible only to classes that belong to both its own family and its own assembly; otherwise,false
.
This property is read-only.A Type object's family is defined as all objects of the exact same Type and of its subclasses.
Reflection
System.Type Class, System Namespace
public bool IsNestedFamORAssem { get; }
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.
true
if the Type is nested and visible only to classes that belong to its own family or to its own assembly; otherwise,false
.
This property is read-only.A Type object's family is defined as all objects of the exact same Type and of its subclasses.
Reflection
System.Type Class, System Namespace
public bool IsNestedFamily { get; }
Gets a Boolean value indicating whether the current Type is nested and visible only within its own family.
true
if the Type is nested and visible only within its own family; otherwise,false
.
This property is read-only.A Type object's family is defined as all objects of the exact same Type and of its subclasses.
Reflection
System.Type Class, System Namespace
public bool IsNestedPrivate { get; }
Gets a Boolean value indicating whether the current Type is nested and declared private.
true
if the Type is nested and declared private; otherwise,false
.
This property is read-only.
Reflection
System.Type Class, System Namespace
public bool IsNestedPublic { get; }
Gets a Boolean value indicating whether the current Type is a public nested class.
true
if the class is nested and declared public; otherwise,false
.
This property is read-only.
Reflection
System.Type Class, System Namespace
public bool IsNotPublic { get; }
Gets a Boolean value indicating whether the top-level Type is not declared public.
true
if the top-level Type is not declared public; otherwise,false
.
This property is read-only.
Reflection
System.Type Class, System Namespace
public bool IsPointer { get; }
Gets a Boolean value that indicates whether the current Type represents a pointer.
This property is read-only.
true
if the current Type represents a pointer; otherwisefalse
.
This property is read-only.
System.Type Class, System Namespace
public bool IsPrimitive { get; }
Gets a Boolean value indicating whether the current Type is one of the primitive types.
true
if the Type is one of the primitive types; otherwise,false
.
This property is read-only.The primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Char, Double, and Single.
Reflection
System.Type Class, System Namespace
public bool IsPublic { get; }
Gets a Boolean value indicating whether the top-level Type is declared public.
true
if the top-level Type is declared public; otherwise,false
.
This property is read-only.
Reflection
System.Type Class, System Namespace
public bool IsSealed { get; }
Gets a Boolean value indicating whether the current Type is declared sealed.
true
if the Type is declared sealed; otherwise,false
.
Reflection
System.Type Class, System Namespace
public bool IsSpecialName { get; }
Gets a Boolean value indicating whether the current Type has a name that requires special handling.
true
if the Type has a name that requires special handling; otherwise,false
.
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. ]
Reflection
System.Type Class, System Namespace
public bool IsValueType { get; }
Gets a Boolean value that indicates whether the current Type represents a value type.
true
if the current Type represents a value type (structure); otherwisefalse
.
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 .]
System.Type Class, System Namespace
public abstract Module Module { get; }
Gets the module in which the current Type is defined.
A Module that reflects the module in which the current Type is defined.
[Behaviors: This property is read-only.]
Reflection
System.Type Class, System Namespace
public abstract string Namespace { get; }
Gets the namespace of the Type.
A String containing the namespace of the current Type.
[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.]
Reflection
System.Type Class, System Namespace
public override Type ReflectedType { get; }
Gets the type that was used to obtain the current instance.
TheType
object through which the current instance was obtained.
This property is read-only.[Note: This property overrides System.Reflection.MemberInfo.ReflectedType.]
The following example demonstrates the System.Type.ReflectedType property. Although the method m is declared inMyClassA
, its reflected type is obtained fromMyClassB
.
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
Reflection
System.Type Class, System Namespace
public abstract RuntimeTypeHandle TypeHandle { get; }
Gets the handle for the current Type.
The RuntimeTypeHandle for the current Type.
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.
RuntimeInfrastructure
System.Type Class, System Namespace
public ConstructorInfo TypeInitializer { get; }
Gets the initializer for thetype represented by the current instance.
A ConstructorInfo containing the name of the static constructor for the type represented by the current instance
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.]
Reflection
System.Type Class, System Namespace
public abstract Type UnderlyingSystemType { get; }
Returns the system-supplied type that represents the current type.
The underlying system type for the Type.
This property is read-only.[Behaviors: As described above.]
Reflection
System.Type Class, System Namespace