Say I have a base class TestBase where I define a virtual method TestMe()
class TestBase
{
public virtual bool TestMe() { }
}
Now I inherit this class:
class Test1 : TestBase
{
public override bool TestMe() {}
}
Now, using Reflection, I need to find if the method TestMe has been overriden in child class – is it possible?
What I need it for – I am writing a designer visualizer for type “object” to show the whole hierarchy of inheritance and also show which virtual methods were overridden at which level.
Given the type
Test1, you can determine whether it has its ownimplementationdeclaration ofTestMe:If the declaration came from a base type, this will evaluate false.
Note that since this is testing declaration, not true implementation, this will return true if
Test1is also abstract andTestMeis abstract, sinceTest1would have its own declaration. If you want to exclude that case, add&& !GetMethod("TestMe").IsAbstract