It looks like you've basically reimplemented a version of casting in C#