Generate Element casting helper functions