How I can get the calling methods in C#
c#, reflection
Solution
from http://www.csharp-examples.net/reflection-calling-method-name/
using System.Diagnostics;
// get call stack
StackTrace stackTrace = new StackTrace();
// get calling method name
Console.WriteLine(stackTrace.GetFrame(1).GetMethod().Name);
Problem
Possible Duplicate: How can I find the method that called the current method? I need a way to know the name of calling methods in C#. For instance: ``` private void doSomething() { // I need to know who is calling me? (method1 or method2). // do something pursuant to who is calling you? } private void method1() { doSomething(); } private void method2() { doSomething(); } ```