Ejemplo n.º 1
0
        /// <summary>
        /// 添加指定类型的元素到子元素集合的队尾
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="newChild"></param>
        /// <returns></returns>
        public override T AppendChild <T>(T newChild)
        {
            if (newChild == null)
            {
                return(default(T));
            }
            if (newChild.Parent != null)
            {
                throw new InvalidOperationException();
            }

            MetaElement lastChild = this.LastChild;
            MetaElement element2  = newChild;

            if (lastChild == null)
            {
                element2.Next   = element2;
                this._lastChild = element2;
            }
            else
            {
                element2.Next   = lastChild.Next;
                lastChild.Next  = element2;
                this._lastChild = element2;
            }
            newChild.Parent = this;

            return(newChild);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 移除所有的子元素
        /// </summary>
        public override void RemoveAllChildren()
        {
            MetaElement element2;

            for (MetaElement element = this.FirstChild; element != null; element = element2)
            {
                element2 = element.NextSibling();
                this.RemoveChild <MetaElement>(element);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 根据下标获取元素
 /// </summary>
 /// <param name="index"></param>
 /// <returns></returns>
 public override MetaElement GetItem(int index)
 {
     if (this._container.HasChildren)
     {
         for (MetaElement element = this._container.FirstChild; element != null; element = element.NextSibling())
         {
             if (index == 0)
             {
                 return(element);
             }
             index--;
         }
     }
     throw new ArgumentOutOfRangeException("index");
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 添加元素到子元素集合的队尾
 /// </summary>
 /// <param name="element"></param>
 private void AddElement(MetaElement element)
 {
     element.Parent = this;
     if (this._lastChild == null)
     {
         element.Next    = element;
         this._lastChild = element;
     }
     else
     {
         element.Next         = this._lastChild.Next;
         this._lastChild.Next = element;
         this._lastChild      = element;
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取枚举器
        /// </summary>
        /// <returns></returns>
        public override IEnumerator <MetaElement> GetEnumerator()
        {
            if (!this._container.HasChildren || (this._container.FirstChild == null))
            {
                goto labl_ret;
            }
            MetaElement firstChild = this._container.FirstChild;

            while (firstChild != null)
            {
                yield return(firstChild);

                firstChild = firstChild.NextSibling();
            }
            labl_ret :;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 移除指定类型的子元素
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="oldChild"></param>
        /// <returns></returns>
        public override T RemoveChild <T>(T oldChild)
        {
            if (oldChild == null)
            {
                return(default(T));
            }
            if (oldChild.Parent != this)
            {
                throw new InvalidOperationException();
            }

            T           local   = oldChild;
            MetaElement element = this._lastChild;

            if (local == this.FirstChild)
            {
                if (local == this._lastChild)
                {
                    this._lastChild = null;
                }
                else
                {
                    MetaElement next = local.Next;
                    element.Next = next;
                }
            }
            else if (local == this._lastChild)
            {
                MetaElement element3 = local.PreviousSibling();
                MetaElement element4 = local.Next;
                element3.Next   = element4;
                this._lastChild = element3;
            }
            else
            {
                MetaElement element5 = local.PreviousSibling();
                MetaElement element6 = local.Next;
                element5.Next = element6;
            }
            local.Next   = null;
            local.Parent = null;

            return(local);
        }
Ejemplo n.º 7
0
 public ChildElements(MetaElement container)
 {
     this._container = container;
 }