How to copy GameObject and preserve Prefab connection and Component values from editor script

Not pretty but it works (tested in 2019.3).

            Selection.activeGameObject = someGameObjectToCopy;
            Unsupported.CopyGameObjectsToPasteboard();
            Unsupported.PasteGameObjectsFromPasteboard();
            var copy = Selection.activeGameObject;