예제 #1
0
        /**
         * @ 读取 xml 节点到字典
         * @ nodes xml节点集合
         * */
        private void ReaderXml(IEnumerable <XElement> nodes)
        {
            if (nodes.Count() == 0)
            {
                return;
            }
            foreach (var n in nodes)
            {
                string  key = n.Name.LocalName.ToLower();
                XmlDict xd  = new XmlDict();
                xd.Tag   = key;
                xd.Order = Count;
                if (n.HasElements)
                {
                    xd.ReaderXml(n.Elements());
                }
                else
                {
                    xd.Value = n.Value;
                }

                if (this.ContainsKey(key))
                {
                    key = string.Format("{0} {1}", key, Count);
                }

                this.Add(key, xd);
            }
        }
예제 #2
0
 /**
  * @ 使用提供的 XmlWriter 对象,将当前字典写入 XmlWriter 流中
  * @ writer 已初始化的 XmlWriter 对象
  * */
 public override void WriterXml(XmlWriter writer)
 {
     writer.WriteStartElement(Tag);
     foreach (var key in this.Keys)
     {
         writer.WriteStartElement(key);
         object  objVal = properties[key];
         XmlDict xd     = objVal as XmlDict;
         if (xd.HasChildren)
         {
             xd.WriterXml(writer);
         }
         else
         {
             writer.WriteString(xd.Value.ToString());
         }
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
 }
예제 #3
0
        /**
         * @ 索引,区分 Hashtable 和 IList 对象
         * @ key 如果当前对象的值是 LdfHashtable 对象,则 key 应当为 hash key
         * @ 如果当前对象值类型为 IList,则自动将 key 转换成下标
         * */
        public override IPListNode this[string key]
        {
            get
            {
                if (!this.ContainsKey(key))
                {
                    return(null);
                }

                object objVal = properties[key];
                if (objVal == null)
                {
                    return(null);
                }

                XmlDict xd = objVal as XmlDict;
                return(xd);
            }
            set
            {
                value.Order     = Count + 1;
                properties[key] = value;
            }
        }