Seeing as C# can\'t switch
on a Type (which I gather wasn\'t added as a special case because is
relationships mean that more than one distinct
I such cases I usually end up with a list of predicates and actions. Something along these lines:
class Mine {
static List> predicates;
static List> actions;
static Mine() {
AddAction(o => o.Hop());
AddAction(o => o.Skip());
}
static void AddAction(Action action) {
predicates.Add(o => o is T);
actions.Add(o => action((T)o);
}
static void RunAction(object o) {
for (int i=0; o < predicates.Count; i++) {
if (predicates[i](o)) {
actions[i](o);
break;
}
}
}
void Foo(object o) {
RunAction(o);
}
}