得到调用方法的类。
class A
{
B b;
public void GetSomething()
{
b=new B();
b.GetSomething();
}
}
calss B
{
public void GetSomething()
{
StackTrace st = new StackTrace(false);
StackFrame sf = st.GetFrame(1);
return sf.GetMethod().ReflectedType.Name; //将会输出 A,也就得到了类A的名字。
//其实从sf.GetMethod()可以得到绝大多数调用GetSomething()的信息
}
}
{
B b;
public void GetSomething()
{
b=new B();
b.GetSomething();
}
}
calss B
{
public void GetSomething()
{
StackTrace st = new StackTrace(false);
StackFrame sf = st.GetFrame(1);
return sf.GetMethod().ReflectedType.Name; //将会输出 A,也就得到了类A的名字。
//其实从sf.GetMethod()可以得到绝大多数调用GetSomething()的信息
}
}