1

Stats: Visual Studio 2015 C# Selenium Webdriver 2.53.1 Internet Explorer 11

Trying to add the Method Names to my reporting for clarity. I am using

    MethodBase m = System.Reflection.MethodBase.GetCurrentMethod();

I then call

 m.Name  

expecting to see the method name but instead in my reporting it calls ".ctor()"

Any advice on how to call the actual method name instead?

leppie
  • 115,091
  • 17
  • 196
  • 297
Andy Williams
  • 879
  • 1
  • 14
  • 33

1 Answers1

2

ctor() is the default constructor for a class. That means you are calling GetCurrentMethod() while the class you are calling it from is still being constructed.

You might also want to get the class name (see here):

string className = MethodBase.GetCurrentMethod().DeclaringType.Name;
Community
  • 1
  • 1
Florian-Rh
  • 777
  • 8
  • 26
  • 1
    Or that the code provided is a field in the class- the field initializer would be called during class construction. – Chris Shain Aug 15 '16 at 14:02