Exemple #1
0
 internal FreeTextNode( IHtmlFragment fragment, IHtmlNodeFactory factory )
   : base( fragment, factory )
 {
   TextNode = Node as IHtmlTextNode;
   if ( TextNode == null )
     throw new InvalidOperationException();
 }
Exemple #2
0
 public FreeComment( IHtmlFragment fragment, HtmlNodeFactory factory )
   : base( fragment, factory )
 {
   Comment = Node as IHtmlComment;
   if ( Comment == null )
     throw new InvalidOperationException();
 }
Exemple #3
0
 internal FreeElement( IHtmlFragment fragment, IHtmlNodeFactory factory )
   : base( fragment, factory )
 {
   Element = Node as IHtmlElement;
   if ( Element == null )
     throw new InvalidOperationException();
 }
Exemple #4
0
        /// <summary>
        /// 尝试使用指定的 HTML 碎片替换此节点
        /// </summary>
        /// <param name="node">要被替换的节点</param>
        /// <param name="fragment">替换节点的 HTML 碎片</param>
        /// <returns>碎片置入后产生的节点集</returns>
        /// <exception cref="System.InvalidOperationException">若节点和碎片不在同一文档</exception>
        public static IEnumerable <IHtmlNode> ReplaceWith(this IHtmlNode node, IHtmlFragment fragment)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

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

            if (!object.Equals(fragment.Document, node.Document))
            {
                throw new InvalidOperationException();
            }

            var container = node.Container;

            lock ( container )
            {
                int index = node.NodesIndexOfSelf();
                Remove(node);
                return(fragment.Into(container, index));
            }
        }
Exemple #5
0
 internal FreeTextNode(IHtmlFragment fragment, IHtmlNodeFactory factory)
     : base(fragment, factory)
 {
     TextNode = Node as IHtmlTextNode;
     if (TextNode == null)
     {
         throw new InvalidOperationException();
     }
 }
Exemple #6
0
 public FreeComment(IHtmlFragment fragment, HtmlNodeFactory factory)
     : base(fragment, factory)
 {
     Comment = Node as IHtmlComment;
     if (Comment == null)
     {
         throw new InvalidOperationException();
     }
 }
Exemple #7
0
 internal FreeElement(IHtmlFragment fragment, IHtmlNodeFactory factory)
     : base(fragment, factory)
 {
     Element = Node as IHtmlElement;
     if (Element == null)
     {
         throw new InvalidOperationException();
     }
 }
Exemple #8
0
        /// <summary>
        /// 创建碎片的副本
        /// </summary>
        /// <param name="fragment">要创建副本的碎片</param>
        /// <returns>碎片的副本</returns>
        public static IHtmlFragment MakeCopy(this IHtmlFragment fragment)
        {
            if (fragment == null)
            {
                throw new ArgumentNullException("fragment");
            }


            var _fragment = fragment.Document.CreateFragment();

            foreach (var node in fragment.Nodes())
            {
                _fragment.AddCopy(node);
            }


            return(_fragment);
        }
    /// <summary>
    /// 在自己前面添加一个文档碎片
    /// </summary>
    /// <param name="node">要在其前面添加碎片的节点</param>
    /// <param name="fragment">要添加 HTML 碎片</param>
    /// <returns>添加后的节点集</returns>
    public static IEnumerable<IHtmlNode> AddFragmentBeforeSelf( this IHtmlNode node, IHtmlFragment fragment )
    {
      if ( node == null )
        throw new ArgumentNullException( "node" );

      if ( fragment == null )
        throw new ArgumentNullException( "fragment" );

      var container = node.Container;


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

      lock ( container.SyncRoot )
      {
        return container.AddFragment( node.NodesIndexOfSelf(), fragment );
      }
    }
            /// <summary>
            /// 将文档碎片编译成一个动态方法,为下一步转换成委托做准备。
            /// </summary>
            /// <param name="fragment">要编译的文档碎片</param>
            /// <returns>编译好的动态方法</returns>
            private static DynamicMethod CompileDynamicMethod(IHtmlFragment fragment)
            {
                throw new NotImplementedException();

                var method = new DynamicMethod("", typeof(IHtmlFragment), new[] { typeof(IHtmlFragmentManager) });

                var il = method.GetILGenerator();


                il.DeclareLocal(typeof(IHtmlContainer));

                il.Emit(OpCodes.Ldarg_0);                   //ld manager         manager


                EmitCreateFragment(il, fragment);           //create fragment    manager fragment


                il.Emit(OpCodes.Callvirt, CompleteDocument); //complete document  document


                il.Emit(OpCodes.Ret);

                return(method);
            }
Exemple #11
0
 internal FreeNode(IHtmlFragment fragment, IHtmlNodeFactory factory)
 {
     _fragment = fragment;
     _factory  = factory;
     Node      = _fragment.Nodes().First();
 }
Exemple #12
0
 internal FreeNode( IHtmlFragment fragment, IHtmlNodeFactory factory )
 {
   _fragment = fragment;
   _factory = factory;
   Node = _fragment.Nodes().First();
 }
Exemple #13
0
        /// <summary>
        /// 在自己前面添加一个文档碎片
        /// </summary>
        /// <param name="node">要在其前面添加碎片的节点</param>
        /// <param name="fragment">要添加 HTML 碎片</param>
        /// <returns>添加后的节点集</returns>
        public static IEnumerable <IHtmlNode> AddFragmentBeforeSelf(this IHtmlNode node, IHtmlFragment fragment)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

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

            var container = node.Container;


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

            lock (container.SyncRoot)
            {
                return(container.AddFragment(node.NodesIndexOfSelf(), fragment));
            }
        }
Exemple #14
0
        /// <summary>
        /// 添加一个文档碎片
        /// </summary>
        /// <param name="container">要添加碎片的容器</param>
        /// <param name="index">要添加的位置</param>
        /// <param name="fragment">要添加的碎片</param>
        /// <returns></returns>
        public static IEnumerable <IHtmlNode> AddFragment(this IHtmlContainer container, int index, IHtmlFragment fragment)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

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


            return(fragment.Into(container, index));
        }
Exemple #15
0
        /// <summary>
        /// 添加一个文档碎片
        /// </summary>
        /// <param name="container">要添加碎片的容器</param>
        /// <param name="fragment">要添加的碎片</param>
        /// <returns></returns>
        public static IEnumerable <IHtmlNode> AddFragment(this IHtmlContainer container, IHtmlFragment fragment)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

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



            lock (container.SyncRoot)
            {
                return(AddFragment(container, container.Nodes().Count(), fragment));
            }
        }
            private static void EmitCreateFragment( ILGenerator il, IHtmlFragment fragment )
            {
                throw new NotImplementedException();

                il.Emit( OpCodes.Callvirt, CreateFragment );        //create fragment manager fragment
            }
            /// <summary>
            /// 将文档碎片编译成一个动态方法,为下一步转换成委托做准备。
            /// </summary>
            /// <param name="fragment">要编译的文档碎片</param>
            /// <returns>编译好的动态方法</returns>
            private static DynamicMethod CompileDynamicMethod( IHtmlFragment fragment )
            {
                throw new NotImplementedException();

                var method = new DynamicMethod( "", typeof( IHtmlFragment ), new[] { typeof( IHtmlFragmentManager ) } );

                var il = method.GetILGenerator();

                il.DeclareLocal( typeof( IHtmlContainer ) );

                il.Emit( OpCodes.Ldarg_0 );                         //ld manager         manager

                EmitCreateFragment( il, fragment );                 //create fragment    manager fragment

                il.Emit( OpCodes.Callvirt, CompleteDocument );      //complete document  document

                il.Emit( OpCodes.Ret );

                return method;
            }
            private static void EmitCreateFragment(ILGenerator il, IHtmlFragment fragment)
            {
                throw new NotImplementedException();

                il.Emit(OpCodes.Callvirt, CreateFragment);  //create fragment manager fragment
            }