public static bool ModifyIndividual(IBaseWindow baseWin, ref GEDCOMIndividualRecord indivRec,
                                            GEDCOMIndividualRecord target, TargetMode targetMode, GEDCOMSex needSex)
        {
            bool result;

            try {
                baseWin.Context.BeginUpdate();
                GEDCOMTree tree = baseWin.Context.Tree;

                using (var dlg = AppHost.Container.Resolve <IPersonEditDlg>(baseWin)) {
                    bool exists = (indivRec != null);
                    if (!exists)
                    {
                        indivRec = new GEDCOMIndividualRecord(tree, tree, "", "");
                        indivRec.InitNew();

                        indivRec.AddPersonalName(new GEDCOMPersonalName(tree, indivRec, "", ""));
                        baseWin.Context.CreateEventEx(indivRec, "BIRT", "", "");
                    }

                    try {
                        baseWin.Context.LockRecord(indivRec);

                        dlg.Person = indivRec;

                        if (targetMode != TargetMode.tmNone)
                        {
                            if (needSex == GEDCOMSex.svMale || needSex == GEDCOMSex.svFemale)
                            {
                                dlg.SetNeedSex(needSex);
                            }
                            dlg.TargetMode = targetMode;
                            dlg.Target     = target;
                        }

                        result = (AppHost.Instance.ShowModalX(dlg, false));
                    } finally {
                        baseWin.Context.UnlockRecord(indivRec);
                    }

                    if (!exists)
                    {
                        if (result)
                        {
                            PostProcessPerson(baseWin, indivRec);

                            tree.AddRecord(indivRec);
                        }
                        else
                        {
                            indivRec.Clear();
                            indivRec.Dispose();
                            indivRec = null;
                        }
                    }
                }
            } finally {
                baseWin.Context.EndUpdate();
            }

            return(result);
        }