Thanks for sharing more context. I see what you were trying to illustrate with your earlier examples now.
Why not make a little library so you can do these kinds of things safely without reimplementing them every project? Maybe call it safeCopy or something.
Why not make a little library so you can do these kinds of things safely without reimplementing them every project? Maybe call it safeCopy or something.