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
  • 3,966
  • 8
  • 29
  • 43
Mr. Boy
  • 57,008
  • 88
  • 294
  • 540

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,219
  • 1
  • 15
  • 29