IfcDoc.FormEdit.LoadInstance C# (CSharp) Méthode

LoadInstance() private méthode

private LoadInstance ( TreeNode tnParent, SEntity instance ) : void
tnParent TreeNode
instance SEntity
Résultat void
        private void LoadInstance(TreeNode tnParent, SEntity instance)
        {
            if (instance == null)
                return;

            // recursion stop limit (if user hits star button)
            if (tnParent != null && tnParent.Level > 32)
                return;

            if (tnParent != null && tnParent.Nodes.Count > 0 && tnParent.Nodes[0].Tag != null)
            {
                return;
            }

            if (tnParent != null)
            {
                tnParent.Nodes.Clear(); // remove placeholder
            }

            Dictionary<string, DocObject> mapEntity = new Dictionary<string, DocObject>();
            Dictionary<string, string> mapSchema = new Dictionary<string, string>();
            BuildMaps(mapEntity, mapSchema);

            Type t = instance.GetType();
            DocDefinition docDef = this.m_project.GetDefinition(t.Name);
            if (docDef is DocEntity)
            {
                DocEntity docEntity = (DocEntity)docDef;
                List<DocAttribute> listAttr = new List<DocAttribute>();
                FormatPNG.BuildAttributeList(docEntity, listAttr, mapEntity);
                foreach (DocAttribute docAttr in listAttr)
                {
                    object value = null;
                    System.Reflection.FieldInfo field = t.GetField(docAttr.Name);
                    if (field != null)
                    {
                        value = field.GetValue(instance);

                        // drill into underlying value
                        if (value != null && !(value is SEntity))
                        {
                            System.Reflection.FieldInfo fValue = value.GetType().GetField("Value");
                            if (fValue != null)
                            {
                                value = fValue.GetValue(value);
                            }
                        }
                    }

                    if (value != null)
                    {
                        TreeNode tn = new TreeNode();
                        tn.Tag = docAttr;
                        tn.Text = docAttr.Name;
                        if (value is SEntity)
                        {
                            tn.Text += " = " + value.GetType().Name;//((SEntity)value).OID;
                        }
                        else if (value is System.Collections.IList)
                        {
                            System.Collections.IList list = (System.Collections.IList)value;
                            tn.Text += " = [" + list.Count + "]";
                        }
                        else if (value != null)
                        {
                            tn.Text += " = " + value.ToString();
                        }

                        if (tnParent != null)
                        {
                            tnParent.Nodes.Add(tn);
                        }
                        else
                        {
                            this.treeViewInstance.Nodes.Add(tn);
                        }

                        if (value is SEntity)
                        {
                            LoadInstance(tn, (SEntity)value);
                        }
                        else if (value is System.Collections.IList)
                        {
                            System.Collections.IList list = (System.Collections.IList)value;
                            for (int i = 0; i < list.Count; i++)
                            {
                                TreeNode tnItem = new TreeNode();
                                tnItem.Tag = list[i];
                                tnItem.Text = (i + 1).ToString() + " = " + list[i].GetType().Name;
                                tn.Nodes.Add(tnItem);

                                TreeNode tnNull = new TreeNode();
                                tnItem.Nodes.Add(tnNull);
                            }
                        }
                    }
                }
            }
        }
FormEdit