I have a couple of classes, all derived from the same base type.
class basetype{}
class TypeA : basetype{}
class TypeB : basetype{}
...
A number of them is stored in a list.
List<basetype> myObjects
As always, each of these types has to be handled differently. Now I have a couple of methods to handle them, and one method that takes the basetype as parameter.
HandleTypes(TypeA obj){}
HandleTypes(TypeB obj){}
HandleTypes(basetype obj)
currently, my HandleAllTypes looks like that:
string name = obj.GetType().Name
switch(name)
{
case "TypeA":
return HandleTypes(obj as TypeA);
case "TypeB":
return HandleTypes(obj as TypeB);
....
}
now this is crap. Is there a way like
HandleTypes(obj ?"as derived type"?)
Searched through MSDN and other sources, found nothing.