I was wondering if it were possible to obtain the run time type of method callers in the stack trace.
Consider the following example:
class Parent
{
public void Foo()
{
var stack = new StackTrace();
foreach (var frame in stack.GetFrames())
{
var methodInfo = frame.GetMethod();
Console.WriteLine("{0} (ReflectedType: {1})", methodInfo.ToString(), methodInfo.DeclaringType);
}
}
}
class Child : Parent
{
}
If I create an instance of Child and call Foo
var child = new Child();
child.Foo();
Foo will print: Void Foo() (ReflectedType: Parent)
Is there any way to get the actual run time types (Child in this case) of method callers in the stack trace?