使用System.Reflection.MethodBase.GetCurrentMethod().Name可以获取当前方法名称。
有没有办法获取上一个方法的名称。
例如:
public static void test()
{
   debug();
}
public static void debug()
{
   // 显示谁调用了debug
   MessageBox.show( xxx );// xxx 为谁调用了他
}

解决方案 »

  1.   

    look into System.Diagnostics.StackTrace class {
      StackTrace st = new StackTrace();for(int i =0; i< st.FrameCount; i++ )
    {
        StackFrame sf = st.GetFrame(i);
        Console.WriteLine("Method: {0}", sf.GetMethod() );
    }   
    }
      

  2.   

    可以了,谢谢!
    public void test()
    {
    debug();
    }
    private void debug()
    {
    StackTrace st = new StackTrace(1, true); StackFrame sf = st.GetFrame(0);
    MessageBox.Show( sf.GetMethod().Name );
    }
      

  3.   

    for(int i =0; i< st.FrameCount; i++ )
    {
        StackFrame sf = st.GetFrame(i);
        Console.WriteLine("Method: {0}", sf.GetMethod() );
    }
    把调用堆栈都列出了