使用System.Reflection.MethodBase.GetCurrentMethod().Name可以获取当前方法名称。
有没有办法获取上一个方法的名称。
例如:
public static void test()
{
debug();
}
public static void debug()
{
// 显示谁调用了debug
MessageBox.show( xxx );// xxx 为谁调用了他
}
有没有办法获取上一个方法的名称。
例如:
public static void test()
{
debug();
}
public static void debug()
{
// 显示谁调用了debug
MessageBox.show( xxx );// xxx 为谁调用了他
}
StackTrace st = new StackTrace();for(int i =0; i< st.FrameCount; i++ )
{
StackFrame sf = st.GetFrame(i);
Console.WriteLine("Method: {0}", sf.GetMethod() );
}
}
public void test()
{
debug();
}
private void debug()
{
StackTrace st = new StackTrace(1, true); StackFrame sf = st.GetFrame(0);
MessageBox.Show( sf.GetMethod().Name );
}
{
StackFrame sf = st.GetFrame(i);
Console.WriteLine("Method: {0}", sf.GetMethod() );
}
把调用堆栈都列出了