Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the name of the current method from code [duplicate]

I know you can do

this.GetType().FullName 

To get

My.Current.Class 

But what can I call to get

My.Current.Class.CurrentMethod 
like image 513
Nick Allen Avatar asked Apr 16 '10 11:04

Nick Allen


People also ask

How do you find the current method name?

The current method name that contains the execution point that is represented by the current stack trace element is provided by the java. lang. StackTraceElement. getMethodName() method.

What is method name in C#?

Method name − Method name is a unique identifier and it is case sensitive. It cannot be same as any other identifier declared in the class. Parameter list − Enclosed between parentheses, the parameters are used to pass and receive data from a method.

How to get the name of current method in C #?

Get name of current method in C# This post will discuss how to get the name of the current method being executed in C#. 1. Using StackTraceClass (System.Diagnostics) A stack trace is an ordered collection of one or more stack frames that store debugging and diagnostic information.

How to get the name of the current method being executed?

This post will discuss how to get the name of the current method being executed in C#. 1. Using StackTraceClass (System.Diagnostics) A stack trace is an ordered collection of one or more stack frames that store debugging and diagnostic information. The following example creates a simple stack trace using the StackTraceinstance.

How to get the name of currently executing method in Java?

Getting name of currently executing method is useful for handling exceptions and debugging purposes. Below are different methods to get currently executing method : Using Throwable Stack Trace : Using Throwable Class : In Java, Throwable class is the superclass of all exceptions and errors in java.lang package.

How to get method name of current thread in a thread?

Using Thread Stack Trace : The Thread.getStackTrace () method returns array of stack trace elements. The second element of the returned array of stack trace contains name of method of current thread. Writing code in comment?


1 Answers

Call System.Reflection.MethodBase.GetCurrentMethod().Name from within the method.

like image 91
Jamie Ide Avatar answered Sep 17 '22 09:09

Jamie Ide