Using System.Reflection to Get a Method's Full Name
You could look at the ReflectedType
of the MethodBase
you get from GetCurrentMethod
, i.e.,
MethodBase method = System.Reflection.MethodBase.GetCurrentMethod();
string methodName = method.Name;
string className = method.ReflectedType.Name;
string fullMethodName = className + "." + methodName;
And to get the full method name with parameters:
var method = System.Reflection.MethodBase.GetCurrentMethod();
var fullName = string.Format("{0}.{1}({2})", method.ReflectedType.FullName, method.Name, string.Join(",", method.GetParameters().Select(o => string.Format("{0} {1}", o.ParameterType, o.Name)).ToArray()));
I think these days, it's best to do this:
string fullMethodName = $"{typeof(MyClass).FullName}.{nameof(MyMethod)}";