Return class name in which a static method resides

c#, static-methods

Solution

Try the following

return typeof(MyClass).Name;

Or also

return MethodBase.GetCurrentMethod().DeclaringType.Name;

Problem

Consider the following code: ``` public class MyClass { public static string MyStaticMethod() { //string className = GetClassNameHere... } } ``` Is it possible to get the name of the class in which the static method resides ? Due to the fact that im using a static method, it is not possible to use the this pointer to retrieve the type of the object that im currently working in.

Original source