1

This is what I am talking about:

Public Shared Sub Test1()
    Test2()
End Sub

Public Shared Sub Test2()
    MsgBox(Test2.LastMethod) ' Test1
End Sub

I would imagine if this is possible, System.Reflection will be utilized?

Any thoughts?

Anders
  • 11,568
  • 34
  • 96
  • 145

3 Answers3

7

Look at the System.Diagnostics.StackFrame class.

 StackFrame frame = new StackFrame(1);
 MethodBase method = frame.GetMethod();
 Console.WriteLine(method.Name);

As a side note you shouldn't depend on who you caller is and shouldn't use this unless you are writing a debugger or for logging purposes.

devdimi
  • 2,412
  • 19
  • 18
1
Dim stackFrame As New Diagnostics.StackFrame(1)
stackFrame.GetMethod.Name.toString() & stackFrame.GetMethod.DeclaringType.FullName.tostring()

Should give you the full name.

Brandon
  • 67,189
  • 30
  • 193
  • 221
0

This question should help:
Can you use reflection to find the name of the currently executing method?

Be careful how you do this. If your method is JIT-inlined you might see the wrong method.

Community
  • 1
  • 1
Joel Coehoorn
  • 380,066
  • 110
  • 546
  • 781