父对象的GetCurrentMethod

时间:2013-05-16 11:04:04

标签: vb.net

有没有办法获取父对象的当前方法?

我可以使用“System.Reflection.MethodInfo.GetCurrentMethod.ToString”获取当前方法。但是我想要一个可以捕获正在执行我的实用程序类(父类)的“GetCurrentMethod”的实用程序类。

1 个答案:

答案 0 :(得分:0)

使用StackTrace类:

Dim st As New StackTrace(True)
Console.WriteLine(st.GetFrame(1).GetMethod())

或者,更好的是,如果您只需要父方法,请使用StackFrame

Dim sf As New StackFrame(1, True)
Console.WriteLine(sf.GetMethod())