2013-05-16 35 views
0

有沒有辦法獲得父對象的當前方法?父對象的GetCurrentMethod

我可以使用「System.Reflection.MethodInfo.GetCurrentMethod.ToString」獲取當前方法。不過,我想要一個實用工具類,它可以捕獲執行我的工具類(父類)的「GetCurrentMethod」。

回答

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()) 
+0

感謝您的幫助! – user2344025