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.
The MemberInfo.DeclaringType property retrieves a reference to the Type object for the type that declares this member. A member of a type is either declared by the type or inherited from a base type, so the Type object returned by the MemberInfo.DeclaringType property might not be the same as the Type object used to obtain the current System.Reflection.MemberInfo object.
If the Type object from which this MemberInfo object was obtained did not declare this member, the MemberInfo.DeclaringType property will represent one of its base types.
If the MemberInfo object is a global member (that is, if it was obtained from the Module.GetMethods method, which returns global methods on a module), the returned MemberInfo.DeclaringType will be null.
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.