c#,get,current,method,name,or,caller,name

rou97 7/29/2016 0

this code wll get you current or caller method names

C#
 [MethodImpl( MethodImplOptions.NoInlining)]
 public MethodBase GetCurrentMethod()
 {
       StackTrace st = new StackTrace();
       StackFrame sf = st.GetFrame(1);

       return sf.GetMethod();
 }

//or caller method name

StackTrace trace = new StackTrace();
int caller = 1;

StackFrame frame = trace.GetFrame(caller);

string callerName = frame.GetMethod().Name;
 

Report Bug

Please Login to Report Bug

Reported Bugs

Comments

Please Login to Comment

Comments