Suppose I have a parent class and a child class:
public abstract class Parent { public string GetParentName() { return GetType().Name; } } public class Child : Parent { public string GetChildName() { return GetType().Name; } }
At current, both GetParentName () and GetChildName () will return Child.
However, in my scenario, I would like to get the name of the class in which the method is declared.
Thus, GetChildName () should return a Child, but GetParentName () should return a parent.
Is it possible?
Note:
I understand that I can use GetType (). BaseType.Name, but this will not work, as the hierarchy can be complex.
source share