Replace static_casts with to* functions for document types.