How to find via reflection if method is overriden

  • Thread starter Thread starter kavboy
  • Start date Start date
K

kavboy

I have a base class A and two inhereted classes B and C.

public class A{
protected virtual bool Method1(){
return true;
}

public bool IsMethod1Overriden{
get {
???????
}
}
}

public class B : A {
protected override bool Method1(){
return true;
}
}

public class С : A {
does not override Method1
}

How can I implement IsMethod1Overriden function?
 
Am I missing something here? How can you ask an object of type class A if
it's method has been overridden?
It's only instances of subclasses that can override the methods, so you can
never have class A return that fact.
You could return false from the method in class A, then override the method
'IsMethod1Overriden' in class B to return true, as it does indeed override
the Method1.

If you need to allow a base class derived object to collect information
from any derived class objects then you can create a virtual method in your
base class, and if a subclass wants to alter the return type then it can
override it. This is similar to what the the Onxxxx methods are that you
often find in classes.

What exactly is it that you are trying to achieve?

Cheers,
Jason
 
Back
Top