casting can not work with runtime classes, it needs to know what to cast to at compile time
sounds like what you want to do is use an interface
basically all your classes that should DoSomething need to implement that interface and in the hit you check if the object implements it, and if so call it