Gets the type that declares the member reflected by the current instance.
The Type object 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.
A member of a class (or interface) is either declared on that type or inherited from a base class (or interface). The MemberInfo.DeclaringType property value cannot 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.
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 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.
The following example demonstrates the difference between the MemberInfo.DeclaringType and MemberInfo.ReflectedType of a member.
C# Example
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.