Esempio n. 1
0
        /// <summary>
        /// 将节点呈现为 HTML
        /// </summary>
        /// <param name="node">要呈现的节点</param>
        /// <param name="context">渲染上下文</param>
        public static void Render(this IHtmlNode node, IHtmlRenderContext context)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }


            foreach (var a in context.RenderAdapters)
            {
                if (a.Render(node, context))
                {
                    return;
                }
            }


            var renderable = node as IHtmlRenderableNode;

            if (renderable != null)
            {
                renderable.Render(context);
                return;
            }

            var element = node as IHtmlElement;

            if (element != null)
            {
                RenderElementAndChilds(element, context);
                return;
            }

            context.Writer.Write(node.OuterHtml());
        }
Esempio n. 2
0
        /// <summary>
        /// 将节点呈现为 HTML
        /// </summary>
        /// <param name="node">要呈现的节点</param>
        /// <param name="writer">HTML 编写器</param>
        /// <param name="adapters">HTML 输出转换器</param>
        public static void Render(this IHtmlNode node, TextWriter writer, params IHtmlAdapter[] adapters)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

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



            if (adapters != null)
            {
                foreach (var a in adapters)
                {
                    if (a.Render(node, writer))
                    {
                        return;
                    }
                }
            }


            var renderable = node as IHtmlRenderableNode;

            if (renderable != null)
            {
                renderable.Render(writer);
                return;
            }

            var element = node as IHtmlElement;

            if (element != null)
            {
                RenderElementAndChilds(element, writer, adapters);
                return;
            }

            writer.Write(node.OuterHtml());
        }