Reputation: 907
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
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