Check before cast if source is the right class for cast.