Esempio n. 1
0
        /// <summary>
        /// 替换指定节点
        /// </summary>
        /// <param name="oldNode">被替换的节点</param>
        /// <param name="newNode">用于替换的节点</param>
        /// <exception cref="System.InvalidOperationException">被替换的节点与用于替换的节点不属于同一个文档</exception>
        public static IHtmlNode Replace(this IHtmlNode oldNode, IFreeNode newNode)
        {
            if (oldNode == null)
            {
                throw new ArgumentNullException("oldNode");
            }

            if (newNode == null)
            {
                throw new ArgumentNullException("newNode");
            }


            var container = oldNode.Container;

            if (container == null)
            {
                throw new InvalidOperationException();
            }

            lock (container.SyncRoot)
            {
                var result = newNode.Into(container, oldNode.NodesIndexOfSelf());
                oldNode.Remove();

                return(result);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 向文档碎片中添加游离节点
        /// </summary>
        /// <param name="index">要添加的位置</param>
        /// <param name="node">要添加的游离节点</param>
        /// <returns>文档碎片自身</returns>
        public virtual HtmlFragment AddNode(int index, IFreeNode node)
        {
            CanAdded(node);

            Nodes.Insert(index, node);

            return(this);
        }
Esempio n. 3
0
        /// <summary>
        /// 向文档碎片中添加游离节点
        /// </summary>
        /// <param name="node">要添加的游离节点</param>
        /// <returns>文档碎片自身</returns>
        public virtual HtmlFragment AddNode(IFreeNode node)
        {
            CanAdded(node);

            Nodes.Add(node);

            return(this);
        }
Esempio n. 4
0
    /// <summary>
    /// 向文档碎片中添加游离节点
    /// </summary>
    /// <param name="index">要添加的位置</param>
    /// <param name="node">要添加的游离节点</param>
    /// <returns>文档碎片自身</returns>
    public virtual HtmlFragment AddNode( int index, IFreeNode node )
    {
      CanAdded( node );

      Nodes.Insert( index, node );

      return this;
    }
Esempio n. 5
0
    /// <summary>
    /// 向文档碎片中添加游离节点
    /// </summary>
    /// <param name="node">要添加的游离节点</param>
    /// <returns>文档碎片自身</returns>
    public virtual HtmlFragment AddNode( IFreeNode node )
    {
      CanAdded( node );

      Nodes.Add( node );

      return this;
    }
Esempio n. 6
0
        /// <summary>
        /// 检查节点是否可以被加入文档碎片。
        /// </summary>
        /// <param name="node">要检查的节点</param>
        public virtual void CanAdded(IFreeNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (!node.Document.Equals(Document))
            {
                throw new InvalidOperationException("不能添加另一文档的游离节点");
            }
        }
Esempio n. 7
0
    /// <summary>
    /// 检查节点是否可以被加入文档碎片。
    /// </summary>
    /// <param name="node">要检查的节点</param>
    public virtual void CanAdded( IFreeNode node )
    {
      if ( node == null )
        throw new ArgumentNullException( "node" );

      if ( !node.Document.Equals( Document ) )
        throw new InvalidOperationException( "不能添加另一文档的游离节点" );
    }
Esempio n. 8
0
        /// <summary>
        /// 在指定位置添加节点
        /// </summary>
        /// <param name="container">要添加节点的容器</param>
        /// <param name="index">要插入节点的位置</param>
        /// <param name="node">要添加的节点</param>
        /// <exception cref="System.InvalidOperationException">添加的节点与节点容器不属于同一个文档</exception>
        public static TContainer Insert <TContainer>(this TContainer container, int index, IFreeNode node) where TContainer : IHtmlContainer
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            if (node == null)
            {
                throw new ArgumentNullException("node");
            }


            var fragment = container as HtmlFragment;

            if (fragment != null)
            {
                fragment.AddNode(index, node);
                return(container);
            }



            lock (container.SyncRoot)
            {
                if (!container.Document.Equals(node.Document))
                {
                    throw new InvalidOperationException();
                }

                node.Into(container, index);

                return(container);
            }
        }
Esempio n. 9
0
 /// <summary>
 /// 在末尾添加节点
 /// </summary>
 /// <param name="container">被添加节点的容器</param>
 /// <param name="node">要添加的节点</param>
 /// <returns>被添加节点的容器</returns>
 /// <exception cref="System.InvalidOperationException">添加的节点与节点容器不属于同一个文档</exception>
 public static TContainer Append <TContainer>(this TContainer container, IFreeNode node) where TContainer : IHtmlContainer
 {
     return(Insert(container, container.Nodes().Count(), node));
 }