Example #1
0
 // 把source插入到this的下级开头位置。返回this
 /// <summary>
 /// 将指定的(源)节点插入到当前节点的子节点开头位置
 /// </summary>
 /// <param name="source">源节点</param>
 /// <returns>当前节点</returns>
 public MarcNode prepend(MarcNode source)
 {
     source.detach();
     this.ChildNodes.insert(0, source);
     source.Parent = this;
     return(this);
 }
Example #2
0
 // 把source插入到this的下级末尾位置。返回this
 /// <summary>
 /// 将指定节点追加到当前节点的子节点尾部
 /// </summary>
 /// <param name="source">要追加的节点</param>
 /// <returns>当前节点</returns>
 public MarcNode append(MarcNode source)
 {
     source.detach();
     this.ChildNodes.add(source);
     source.Parent = this;
     return(this);
 }
Example #3
0
        // 把source插入到this的后面。返回this
        /// <summary>
        /// 将指定节点插入到当前节点的后面兄弟位置
        /// </summary>
        /// <param name="source">要插入的节点</param>
        /// <returns>当前节点</returns>
        public MarcNode after(MarcNode source)
        {
            MarcNode parent = this.Parent;

            // 自己是根节点,无法具有兄弟
            if (parent == null)
            {
                throw new Exception("无法在根节点同级插入新节点");
            }

            int index = parent.ChildNodes.indexOf(this);

            if (index == -1)
            {
                throw new Exception("parent的ChildNodes中居然没有找到自己");
            }

            // 进行类型检查,同级只能插入相同类型的元素
            if (this.NodeType != source.NodeType)
            {
                throw new Exception("无法在节点同级插入不同类型的新节点。this.NodeTYpe=" + this.NodeType.ToString() + ", source.NodeType=" + source.NodeType.ToString());
            }

            source.detach();
            parent.ChildNodes.insert(index + 1, source);
            source.Parent = this.Parent;
            return(this);
        }
Example #4
0
        // 追加
        // 对node先要摘除
        /// <summary>
        /// 在当前集合末尾追加一个节点元素
        /// </summary>
        /// <param name="node">要追加的节点</param>
        public new void add(MarcNode node)
        {
            node.detach();
            base.add(node);

            Debug.Assert(owner != null, "");
            node.Parent = owner;
        }
Example #5
0
 // 把source插入到this的下级开头位置。返回this
 /// <summary>
 /// 将指定的(源)节点插入到当前节点的子节点开头位置
 /// </summary>
 /// <param name="source">源节点</param>
 /// <returns>当前节点</returns>
 public MarcNode prepend(MarcNode source)
 {
     source.detach();
     this.ChildNodes.insert(0, source);
     source.Parent = this;
     return this;
 }
Example #6
0
 // 把source插入到this的下级末尾位置。返回this
 /// <summary>
 /// 将指定节点追加到当前节点的子节点尾部
 /// </summary>
 /// <param name="source">要追加的节点</param>
 /// <returns>当前节点</returns>
 public MarcNode append(MarcNode source)
 {
     source.detach();
     this.ChildNodes.add(source);
     source.Parent = this;
     return this;
 }
Example #7
0
        // 把source插入到this的后面。返回this
        /// <summary>
        /// 将指定节点插入到当前节点的后面兄弟位置
        /// </summary>
        /// <param name="source">要插入的节点</param>
        /// <returns>当前节点</returns>
        public MarcNode after(MarcNode source)
        {
            MarcNode parent = this.Parent;
            // 自己是根节点,无法具有兄弟
            if (parent == null)
                throw new Exception("无法在根节点同级插入新节点");

            int index = parent.ChildNodes.indexOf(this);
            if (index == -1)
            {
                throw new Exception("parent的ChildNodes中居然没有找到自己");
            }

            // 进行类型检查,同级只能插入相同类型的元素
            if (this.NodeType != source.NodeType)
                throw new Exception("无法在节点同级插入不同类型的新节点。this.NodeTYpe="+this.NodeType.ToString()+", source.NodeType="+source.NodeType.ToString());

            source.detach();
            parent.ChildNodes.insert(index+1, source);
            source.Parent = this.Parent;
            return this;
        }
Example #8
0
        // 追加
        // 对node先要摘除
        /// <summary>
        /// 在当前集合末尾追加一个节点元素
        /// </summary>
        /// <param name="node">要追加的节点</param>
        public new void add(MarcNode node)
        {
            node.detach();
            base.add(node);

            Debug.Assert(owner != null, "");
            node.Parent = owner;
        }