Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the name of the current method

This is kind of a silly question, but is it possible to get the name of the method that is currently being executed from within that method?

Public Sub SomeMethod()     Dim methodName as String = System.Reflection.[function to get the current method name here?]  End Sub 

Thanks

like image 652
camainc Avatar asked Jan 12 '10 18:01

camainc


People also ask

How to get the name of the Current method in c#?

Using MethodBase.GetCurrentMethod() method can be used, which returns a MethodBase object representing the currently executing method. That's all about getting the name of the current method in C#.

How can I find the method that called the current method Java?

getMethodName() method returns the name of the method containing the execution point represented by this stack trace element. Thread. currentThread().


2 Answers

System.Reflection.MethodInfo.GetCurrentMethod();

like image 70
herzmeister Avatar answered Oct 10 '22 02:10

herzmeister


The other methods are close to what was asked, but they don't return the string value. But this does:

Dim methodName$ = System.Reflection.MethodBase.GetCurrentMethod().Name 
like image 45
Edward Avatar answered Oct 10 '22 01:10

Edward