IfcDoc.FormEdit.RedirectReference C# (CSharp) Method

RedirectReference() private method

Replaces links from one object to another, such as page references
private RedirectReference ( DocSchema docSchema, DocDefinition docOld, DocDefinition docNew, bool force ) : void
docSchema DocSchema
docOld DocDefinition The old reference to unlink
docNew DocDefinition The new reference to link
force bool If true, redirects even if on same page; if false and on same page, then doesn't redirect
return void
        private void RedirectReference(DocSchema docSchema, DocDefinition docOld, DocDefinition docNew, bool force)
        {
            // find reference to each source and redirect to target definition
            foreach (DocEntity docEntity in docSchema.Entities)
            {
                if (force || (docEntity.DiagramNumber != docOld.DiagramNumber))
                {
                    foreach (DocAttribute docAttr in docEntity.Attributes)
                    {
                        if (docAttr.Definition == docOld)
                        {
                            docAttr.Definition = CreateLink(docNew, docAttr.DiagramLine[0]);
                            this.ctlExpressG.LayoutDefinition(docEntity);
                        }
                    }

                    foreach (DocLine docLine in docEntity.Tree)
                    {
                        if (docLine.Definition == docOld)
                        {
                            docLine.Definition = CreateLink(docNew, docLine.DiagramLine[0]);
                            this.ctlExpressG.LayoutDefinition(docEntity);
                        }
                        foreach (DocLine docNode in docLine.Tree)
                        {
                            if (docNode.Definition == docOld)
                            {
                                docNode.Definition = CreateLink(docNew, docLine.DiagramLine[0]);
                                this.ctlExpressG.LayoutDefinition(docEntity);
                            }
                        }
                    }
                }
            }

            foreach (DocType docType in docSchema.Types)
            {
                if (force || (docType.DiagramNumber != docOld.DiagramNumber))
                {
                    if (docType is DocDefined)
                    {
                        DocDefined docDef = (DocDefined)docType;
                        if (docDef.Definition == docOld)
                        {
                            docDef.Definition = CreateLink(docNew, docDef.DiagramLine[0]);
                            this.ctlExpressG.LayoutDefinition(docDef);
                        }
                    }
                    else if (docType is DocSelect)
                    {
                        DocSelect docSel = (DocSelect)docType;
                        foreach (DocLine docLine in docSel.Tree)
                        {
                            if (docLine.Definition == docOld)
                            {
                                docLine.Definition = CreateLink(docNew, docLine.DiagramLine[0]);
                                this.ctlExpressG.LayoutDefinition(docSel);
                            }
                            foreach (DocLine docNode in docLine.Tree)
                            {
                                if (docNode.Definition == docOld)
                                {
                                    docNode.Definition = CreateLink(docNew, docLine.DiagramLine[0]);
                                    this.ctlExpressG.LayoutDefinition(docSel);//?...
                                }
                            }
                        }
                    }
                }
            }
        }
FormEdit