Exemplo n.º 1
0
        public StringNode <V> AddChild(string key, V value)
        {
            var child = new StringNode <V>(m_tree, key, value);

            AddChild(child);
            return(child);
        }
Exemplo n.º 2
0
 public void AddChild(StringNode <V> child)
 {
     this.Children.Add(child.Name, child);
     child.m_Parent = this;
     child.m_depth  = this.m_depth + 1;
     child.m_indent = this.m_indent + "\t";
 }
Exemplo n.º 3
0
        public StringNode <V> AddChild(string key, V value)
        {
            StringNode <V> child = new StringNode <V>(this.m_tree, key, value);

            this.AddChild(child);
            return(child);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Removes and returns the direct Child with the given key
        /// </summary>
        /// <returns></returns>
        public StringNode <V> FindAndRemoveChild(string[] keyChain, int index)
        {
            StringNode <V> child = this.FindChild(keyChain, index);

            if (child != null)
            {
                child.Remove();
            }
            return(child);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Removes and returns the direct Child with the given key
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public StringNode <V> RemoveChild(string key)
        {
            StringNode <V> child = this.GetChild(key);

            if (child != null)
            {
                child.Remove();
            }
            return(child);
        }
Exemplo n.º 6
0
 public void Remove()
 {
     if (this.m_Parent == null)
     {
         throw new InvalidOperationException("Cannot remove the Root of a Tree.");
     }
     this.m_Parent.Children.Remove(this.m_Name);
     this.m_Parent = (StringNode <V>)null;
     this.m_depth  = 0;
 }
Exemplo n.º 7
0
 public void Remove()
 {
     if (m_Parent == null)
     {
         throw new InvalidOperationException("Cannot remove the Root of a Tree.");
     }
     m_Parent.Children.Remove(m_Name);
     m_Parent = null;
     m_depth  = 0;
 }
Exemplo n.º 8
0
        /// <summary>
        /// Removes and returns the direct Child with the given key
        /// </summary>
        /// <returns></returns>
        public StringNode <V> FindAndRemoveChild(string[] keyChain)
        {
            StringNode <V> child = FindChild(keyChain);

            if (child != null)
            {
                child.Remove();
            }
            return(child);
        }
Exemplo n.º 9
0
        public StringNode <V> AddChildInChain(string[] keyChain, V value)
        {
            StringNode <V> stringNode = this;

            for (int index = 0; index < keyChain.Length; ++index)
            {
                string key = keyChain[index];
                stringNode = stringNode.GetOrCreate(key);
                if (index == keyChain.Length - 1)
                {
                    stringNode.Value = value;
                }
            }

            return(stringNode);
        }
Exemplo n.º 10
0
        public void ReadXml(XmlReader reader)
        {
            if ((object)this.Value != null)
            {
                try
                {
                    this.Value.ReadXml(reader);
                }
                catch (Exception ex)
                {
                    LogUtil.ErrorException(ex, string.Format("Failed to parse Node: {0}", (object)this.FullName),
                                           new object[0]);
                }
            }

            if (this.Children.Count > 0)
            {
                List <StringNode <V> > stringNodeList = new List <StringNode <V> >();
                int num = 0;
                while (num < this.Children.Count)
                {
                    reader.Read();
                    if (reader.ReadState == ReadState.EndOfFile)
                    {
                        throw new Exception("Unexpected EOF in Config.");
                    }
                    reader.SkipEmptyNodes();
                    if (reader.NodeType != XmlNodeType.EndElement)
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            StringNode <V> child = this.GetChild(reader.Name);
                            if (child == null)
                            {
                                this.OnInvalidNode(reader);
                            }
                            else
                            {
                                ++num;
                                stringNodeList.Add(child);
                                if (!reader.IsEmptyElement)
                                {
                                    child.ReadXml(reader);
                                }
                                else
                                {
                                    reader.SkipEmptyNodes();
                                }
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                IEnumerable <StringNode <V> > stringNodes =
                    this.Children.Values.Except <StringNode <V> >((IEnumerable <StringNode <V> >)stringNodeList);
                if (stringNodes.Count <StringNode <V> >() > 0)
                {
                    this.m_tree.OnError("Found {0} missing Node(s): {1}", (object)stringNodes.Count <StringNode <V> >(),
                                        (object)stringNodes.ToString <StringNode <V> >(", ",
                                                                                       (Func <StringNode <V>, object>)(node => (object)node.FullName)));
                }
            }

            reader.SkipEmptyNodes();
            if (reader.IsEmptyElement)
            {
                reader.Read();
            }
            reader.SkipEmptyNodes();
            while (reader.NodeType != XmlNodeType.EndElement)
            {
                this.OnInvalidNode(reader);
                reader.SkipEmptyNodes();
            }

            reader.ReadEndElement();
        }
Exemplo n.º 11
0
        public V FindValue(string[] keyChain, int index)
        {
            StringNode <V> child = this.FindChild(keyChain, index);

            return(child != null ? child.Value : default(V));
        }
Exemplo n.º 12
0
        public V GetValue(string key)
        {
            StringNode <V> child = this.GetChild(key);

            return(child != null ? child.Value : default(V));
        }
Exemplo n.º 13
0
        public V FindValue(string[] keyChain)
        {
            StringNode <V> child = FindChild(keyChain);

            return(child != null ? child.Value : default(V));
        }