fdssdfa

导航

得到调用方法的类。

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()的信息
  }
}

posted on 2005-11-25 15:19  dfsafdas  阅读(212)  评论(0编辑  收藏  举报