Andy Williams
Andy Williams

Reputation: 907

Reflection in C# for my reporting for selenium webdriver

In my reporting I use:

  private string className = "";
    className = this.GetType().Name;

In order to capture the Name of the Class that I am using. Is there a similar way to access at the method level?

Upvotes: 1

Views: 268

Answers (1)

Zapo
Zapo

Reputation: 211

In current .net you can use CallerMemberNameAttribute. You can create method as follows:

public static string GetMethodName([System.Runtime.CompilerServices.CallerMemberName] string memberName = "")
{
    return memberName;
}

Then you just call var name = GetMethodName(); to get current method name.

Upvotes: 1

Related Questions