// ----------------------------------------------------------------------
        void DestroySingleObject(iCS_EditorObject toDestroy)
        {
            if (toDestroy == null || toDestroy.InstanceId == -1)
            {
                return;
            }
            // Disconnect ports linking to this port.
            ExecuteIf(toDestroy, obj => obj.IsPort, _ => DisconnectPort(toDestroy));
            // Update modules runtime data when removing a module port.
            iCS_EditorObject parent = toDestroy.Parent;

            if (toDestroy.IsKindOfPackagePort)
            {
                MoveDynamicPortToLastIndex(toDestroy);
            }
            // Remember entry state.
            bool isEntryState = toDestroy.IsEntryState;

            // Destroy instance.
            toDestroy.DestroyInstance();
            // Reconfigure parent state if the object removed is an entry state.
            if (isEntryState)
            {
                SelectEntryState(parent);
            }
            if (parent != null && parent.IsParentMuxPort)
            {
                CleanupMuxPort(parent);
            }
            if (parent != null && parent.IsNode)
            {
                CleanupEnablePorts(parent);
            }
        }