lundi 15 août 2016

calling a derived class method on a object cast to base class

I have a base class Element and a derived class ViewSheet. When I am collecting all of my ViewSheet objects they are being cast to Element by the collector method. Now I need to call a method on each object called ViewSheet.get_Parameter(). That method only exists on a derived class so cannot be called on Element.

I can find out what derived type is from calling Element.GetType() but then how can I actually cast that object to ViewSheet and then call the ViewSheet.get_Parameter() on it?

Since this happens a lot, I would need to implement some sort of generic method that could accept different base class + derived class combinations. Any ideas will be appreciated.





Aucun commentaire:

Enregistrer un commentaire