0
private string MethodName
{
   get
   {
      MethodBase m = MethodBase.GetCurrentMethod();
      return String.Format("{0}.{1}", m.ReflectedType.Name, m.Name);
   }
}

I'd like to do something like this but of course now the call is made from a different method to the one I want to describe. Is there a simple way around this or an obvious alternative?

croxy
  • 4,082
  • 9
  • 28
  • 46
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589

1 Answers1

2

You can get it from the StackTrace doing something like:

string MethodName
{
    get
    {
        return new StackTrace()
                    .GetFrame(1) // Get previous frame because we want to know the calling method name
                    .GetMethod()
                    .Name;
    }
}
Matteo Umili
  • 3,412
  • 1
  • 19
  • 31