Possible duplicate:
How to find the method that called the current method?
I have a method in an object that is called from several places inside the object. There is a quick and easy way to get the name of a method called this popular method.
Pseudocode EXAMPLE:
public Main() { PopularMethod(); } public ButtonClick(object sender, EventArgs e) { PopularMethod(); } public Button2Click(object sender, EventArgs e) { PopularMethod(); } public void PopularMethod() {
Inside PopularMethod() I would like to see the value Main if it was called from Main ... I would like to see " ButtonClick " if PopularMethod() was called from ButtonClick
I looked at System.Reflection.MethodBase.GetCurrentMethod() , but that will not call me the calling method. I looked at the StackTrace class, but I really didnโt like to run the entire stack trace every time this method is called.
reflection methods c # calling-convention
Scott Vercuski Mar 05 '09 at 18:22 2009-03-05 18:22
source share