System.Reflection.MethodBase.GetCurrentMethod(); give ".ctor"

1.4k views Asked by At

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?

1

There are 1 answers

1
Florian-Rh On

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;