Static inheritance doesn't work like inheritance of normal methods. The behavior you observe happens instead (it acts as a method of the parent class, not of the child). User Daniel Earwicker put it really well in this answer. In short, static methods are tied to their declaring type.
Now, regarding your specific problem, there isn't a way to make what you're trying to do work. There are however a few alternative ways to achieve your desired result. The simplest is to just use a property instead of a method.
public class ReflectionObject
{
public string Name
{
get {
return this.GetType().Name;
}
}
}
Then if you had a method such as this in your child class:
public class DerivedObject : ReflectionObject
{
public string MyName()
{
return this.Name;
}
}
..calling something like new DerivedObject().MyName()
would return "DerivedObject"
as is your desired result. Using this in the property instead of GetType()
is also an option:
MethodBase.GetCurrentMethod().DeclaringType.Name;
Of course, since you don't mention your use case I cannot know of any limitations you may have. Generally, this is the easiest way to get the name of a child class.