public abstract class MemberInfo
Object
MemberInfo
mscorlib
Reflection
Provides access to member metadata.
[Note: MemberInfo is used to represent all members of a type: nested types, fields, events, properties, methods, and constructors. The Base Class Library includes the following derived types:]
System.Reflection Namespace
MemberInfo Constructors
MemberInfo Properties
MemberInfo.DeclaringType Property
MemberInfo.Name Property
MemberInfo.ReflectedType Property
protected MemberInfo();
Constructs a new instance of the MemberInfo class.
System.Reflection.MemberInfo Class, System.Reflection Namespace
public abstract Type DeclaringType { get; }
Gets the type that declares the member reflected by the current instance.
The Typeobject of the class that declares the member reflected by the current instance; or,
null
if the member reflected by the current instance is a global member.
[Note: A member of a class (or interface) is either declared on that type or inherited from a base class (or interface). The System.Reflection.MemberInfo.DeclaringType property value may not be the same as the Type object used to obtain the current instance. These values will differ if either of the following conditions is true.
]
- If the Type object from which the current instance was obtained did not declare the member reflected by the current instance, the System.Reflection.MemberInfo.DeclaringType will represent the base type that is closest to that object in its hierarchy chain and declares the member reflected by the current instance.
- If the current instance reflects a global member, (that is, it was obtained from System.Reflection.Module.GetMethods , which returns global methods on a module), then the System.Reflection.MemberInfo.DeclaringType property value is
null
.
[Behaviors: This property is read-only.
This property is required to return the Type object for the type that declares the member reflected by the current instance. This property value is required to be equal to the System.Reflection.MemberInfo.ReflectedType property value of the current instance if and only if the reflected type also contains a declaration for the member reflected by the current instance.
]
[Overrides: Override this property to get the Type of the class that declared the member that is reflected by the current instance.]
[Usage: Use this property to determine the Type of the class that declared the member that is reflected by the current instance.]
The following example demonstrates the difference between the System.Reflection.MemberInfo.DeclaringTypeand System.Reflection.MemberInfo.ReflectedType of a member.
using System; using System.Reflection; public class BaseClass { public void ReflectedMethod() {} } public class DerivedClass: BaseClass {} public class DeclaringTypeExample { public static void Main() { Type t = typeof(DerivedClass); MemberInfo [] memInfo = t.GetMember("ReflectedMethod"); Console.WriteLine("Reflected type is {0}.", memInfo[0].ReflectedType); Console.WriteLine("Declaring type is {0}.", memInfo[0].DeclaringType); } }The output is
Reflected type is DerivedClass.
Declaring type is BaseClass.
System.Reflection.MemberInfo Class, System.Reflection Namespace
public abstract string Name { get; }
Gets the name of the member reflected by the current instance.
A String containing the name of the member reflected by the current instance.
[Behaviors: This property is read-only.Only the simple name, not the fully qualified name, of the member reflected by the current instance is returned.
[Note: For example, if the current instance reflects the member
System.MyClass
, the System.Reflection.MemberInfo.Name property would be "Print".]
]
System.Reflection.MemberInfo Class, System.Reflection Namespace
public abstract Type ReflectedType { get; }
Gets the type of the class through which the current instance was obtained.
The Typeobject for the class through which the current instance was obtained.
[Behaviors: This property is read-only.
ReflectedType
is required to get the type of the object that was used to obtain the current instance. This property value is required to be equal to the System.Reflection.MemberInfo.DeclaringType property value of the current instance if and only if the reflected type also contains a declaration for the member reflected by the current instance.]
System.Reflection.MemberInfo Class, System.Reflection Namespace