Could anyone please tell the difference between these 2 Properties?
DeclaringType
and ReflectedType
Consider the code is:
public class TestClass
{
public static void TestMethod()
{
Console.WriteLine("Method in Class", MethodBase.GetCurrentMethod().DeclaringType.Name);
Console.WriteLine("Method in Class", MethodBase.GetCurrentMethod().ReflectedType.Name);
}
}
Are these same and Can be used interchangeably?
ReflectedType
exists: In my opinion, it is a .NET 1.0 design mistake. They probably had a rather specific scenario in mind. I consider it to be better to keep track of theType
yourself instead of adding this hack to reflection objects.