C# Method Caller

.net, c#

Solution

These articles should be of help:

- http://iridescence.no/post/GettingtheCurrentStackTrace.aspx

- http://blogs.msdn.com/jmstall/archive/2005/03/20/399287.aspx

Basically the code looks like this:

StackFrame frame = new StackFrame(1);
MethodBase method = frame.GetMethod();
message = String.Format("{0}.{1} : {2}",
method.DeclaringType.FullName, method.Name, message);
Console.WriteLine(message);

Problem

Possible Duplicate: How can I find the method that called the current method? Hi, how can i determine the caller of a method from within the method? Eg: ``` SomeNamespace.SomeClass.SomeMethod() { OtherClass(); } OtherClass() { // Here I would like to able to know that the caller is SomeNamespace.SomeClass.SomeMethod } ``` Thanks

Original source

Related problems