I have a base class and some derived classes that have some static methods. Is it possible to run static method if I know only the object of base class.
Ive tried typeof and getType methods to do it but as I realised they give only the Type. I know that my issue can be solved by comparing Type with my classes and finally it will work fine. But I hope that better pattern exists.
Type type = building.GetType();
type.arrangeCeremony(); // arrange ceremony is public static method in all derived classes
Thanks for your answers
If the operation depends on the type: the most reasonable way to implement that is simply: polymorphism.
So: make the method non-static and move it to a base-type, as either
virtualorabstract, and thenoverrideit in the sub-types. Then you don't need to ask the building what type it is: you just use polymorphismIf not all types can sensibly implement the method, then perhaps create an
interface, or have the method declared at some sensible intermediate type level, and use a type test:or