Я пишу класс ExceptionFactory, используя System.Diagnostics.StackTrace
.
var trace = new StackTrace(1, true);
var frames = trace.GetFrames();
var method = frames[0].GetMethod();
Теперь для классов
class Base
{
public void Foo()
{
//Call ExceptionFactory from here
}
}
class A : Base {}
//...
var x = new A();
x.Foo();
method.DeclaringType
вернется typeof(Base)
. Однако мне нужно typeof(A)
. Можно ли как-нибудь получить?
method.ReflectedType
тоже не работает.