Search code examples
c#.net.net-3.5function

Get the calling function name from the called function


Possible Duplicate:
How can I find the method that called the current method?

How can I get the calling function name from the called function in C#?


Solution

  • new StackFrame(1, true).GetMethod().Name
    

    Note that in release builds the compiler might inline the method being called, in which case the above code would return the caller of the caller, so to be safe you should decorate your method with:

    [MethodImpl(MethodImplOptions.NoInlining)]