I have a function which accepts two base class parameters. Within this function I wish to test the types of these parameters over a number of derived classes and then call a polymorphic function. See below to see my first attempt which won't compile.
public static double Intersect(baseClass s0, baseClass s1)
{
if (s1 is derivedClassB) return (s0 as derivedClassA).PolyMethod((derivedClassB)s1);
else if (s1 is derivedClassC) return (s0 as derivedClassA).PolyMethod((derivedClassC)s1);
else return 0.0;
}
I thought i could use something like
Type dType = s0.GetType();
(s0 as dType).PolyMethod(derivedClassB) s1);
but this doesn't work either.