Пример #1
0
        public MetaDataTreeNode intersection(MetaDataTreeNode tree)
        {
            MetaDataTreeNode result = null;

            if (this.Equals(tree))
            {
                result = MetaDataTreeNodeFactory.copy(tree);

                foreach (MetaDataTreeNode a in Child)
                {
                    foreach (MetaDataTreeNode b in tree.Child)
                    {
                        MetaDataTreeNode intersection = a.intersection(b);
                        if (intersection != null)
                        {
                            intersection.Parent = result;
                            result.insertChild(intersection);
                            break;
                        }
                    }
                }
            }

            return(result);
        }
Пример #2
0
        public void insertNode(string name, string value)
        {
            string head = "";
            string tail = "";

            MetaDataTreeNode.Type type = MetaDataTreeNode.Type.ARRAY;

            for (int i = 0; i < name.Length; i++)
            {
                if (name[i] == '[' || name[i] == ':' || name[i] == '/')
                {
                    if (i != 0)
                    {
                        tail = name.Substring(i);

                        if (name[i] == '[')
                        {
                            type = MetaDataTreeNode.Type.ARRAY;
                        }
                        else if (name[i] == ':')
                        {
                            type = MetaDataTreeNode.Type.NAMESPACE;
                        }
                        else if (name[i] == '/')
                        {
                            type = MetaDataTreeNode.Type.STRUCT;
                        }
                        break;
                    }
                    else if (name[i] == '[')
                    {
                        head += name[i];
                    }
                }
                else
                {
                    head += name[i];
                }
            }

            MetaDataTreeNode node = getChild(head);

            if (node == null)
            {
                if (string.IsNullOrEmpty(tail))
                {
                    node = new MetaDataTreeValue(value);

                    if (this.NodeType == Type.ARRAY)
                    {
                        node.parent = this;
                        insertChild(node);
                    }
                    else
                    {
                        MetaDataTreeProperty prop = new MetaDataTreeProperty(head);
                        prop.parent = this;
                        node.parent = prop;
                        prop.insertChild(node);

                        insertChild(prop);
                    }
                }
                else
                {
                    if (this.NodeType == Type.ARRAY)
                    {
                        node = MetaDataTreeNodeFactory.create("", type);
                    }
                    else
                    {
                        node = MetaDataTreeNodeFactory.create(head, type);
                    }
                    node.parent = this;

                    insertChild(node);
                    node.insertNode(tail, value);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(tail))
                {
                    if (node.type == Type.VALUE)
                    {
                        node.Data = value;
                    }
                    else
                    {
                        MetaDataTreeProperty prop = (MetaDataTreeProperty)(node);
                        prop.Value = value;
                    }
                }
                else
                {
                    if (node.type == type)
                    {
                        node.insertNode(tail, value);
                    }
                    else
                    {
                        MetaDataTreeLanguage lang = new MetaDataTreeLanguage(value);
                        MetaDataTreeArray    arr  = (MetaDataTreeArray)(node);
                        arr.insertChild("[1]", lang);
                    }
                }
            }
        }