Reputation: 12560
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?
Upvotes: 1
Views: 216
Reputation: 415630
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.
Upvotes: 0
Reputation: 69973
Dim stackFrame As New Diagnostics.StackFrame(1)
stackFrame.GetMethod.Name.toString() & stackFrame.GetMethod.DeclaringType.FullName.tostring()
Should give you the full name.
Upvotes: 1
Reputation: 2462
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.
Upvotes: 7