I'm writing an ExceptionFactory class, using System.Diagnostics.StackTrace
.
var trace = new StackTrace(1, true);
var frames = trace.GetFrames();
var method = frames[0].GetMethod();
Now, for classes
class Base
{
public void Foo()
{
//Call ExceptionFactory from here
}
}
class A : Base {}
//...
var x = new A();
x.Foo();
method.DeclaringType
would return typeof(Base)
. However, I need typeof(A)
. Is it possible to get somehow?
method.ReflectedType
doesn't work either.