Difference between DeclaringType and ReflectedType
Solution 1:
They're not exactly the same.
-
DeclaringType
returns the type that declares the method. -
ReflectedType
returns theType
object that was used to retrieve the method.
Here's a demo:
MemberInfo m1 = typeof(Base).GetMethod("Method");
MemberInfo m2 = typeof(Derived).GetMethod("Method");
Console.WriteLine(m1.DeclaringType); //Base
Console.WriteLine(m1.ReflectedType); //Base
Console.WriteLine(m2.DeclaringType); //Base
Console.WriteLine(m2.ReflectedType); //Derived
public class Base
{
public void Method() {}
}
public class Derived : Base { }
Noticed how the last line printed Derived
instead of Base
. That's because, even though Method
is declared on Base
, we used Derived
to obtain the MemberInfo
object.
Source: MSDN