I may be missing the point entirely here, but what's wrong with the string "MyClass"?
public class MyClass
{
public static string MyStaticMethod()
{
string className = "MyClass";
Console.WriteLine(className);
}
}
You may argue that if MyClass is inherited, you would want the name of the inherited class instead. Then consider the following:
public class MyClass
{
public static string MyStaticMethod()
{
string className = typeof(MyClass).Name;
Console.WriteLine(className);
}
}
public class MyOtherClass : MyClass{ }
Now, what do you think you will see in the Console if you invoke MyOtherClass.SomeMethod
? The answer is "MyClass
". So, looking up the class name dynamically will give you the exact same result as simply typing it in a string. The only upside I can see with getting it through Reflection is that it will still render the correct result if you rename the class.