Exemple #1
0
        public void WriteTo(TextWriter writer, HtmlEncoder encoder)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (encoder == null)
            {
                throw new ArgumentNullException(nameof(encoder));
            }

            switch (TagRenderMode)
            {
            case TagRenderMode.StartTag:
                writer.Write('<');
                writer.Write(TagName);
                AppendAttributes(writer, encoder);
                writer.Write('>');
                break;

            case TagRenderMode.EndTag:
                writer.Write("</");
                writer.Write(TagName);
                writer.Write('>');
                break;

            case TagRenderMode.SelfClosing:
                writer.Write('<');
                writer.Write(TagName);
                AppendAttributes(writer, encoder);
                writer.Write(" />");
                break;

            default:
                writer.Write('<');
                writer.Write(TagName);
                AppendAttributes(writer, encoder);
                writer.Write('>');
                InnerHtml.WriteTo(writer, encoder);
                writer.Write("</");
                writer.Write(TagName);
                writer.Write('>');
                break;
            }
        }
Exemple #2
0
        /// <inheritdoc />
        public void WriteTo(TextWriter writer, HtmlEncoder encoder)
        {
            var htmlTextWriter = writer as HtmlTextWriter;

            if (htmlTextWriter != null)
            {
                // As a perf optimization, we can buffer this output rather than writing it
                // out character by character.
                htmlTextWriter.Write(this);
                return;
            }

            switch (TagRenderMode)
            {
            case TagRenderMode.StartTag:
                writer.Write("<");
                writer.Write(TagName);
                AppendAttributes(writer, encoder);
                writer.Write(">");
                break;

            case TagRenderMode.EndTag:
                writer.Write("</");
                writer.Write(TagName);
                writer.Write(">");
                break;

            case TagRenderMode.SelfClosing:
                writer.Write("<");
                writer.Write(TagName);
                AppendAttributes(writer, encoder);
                writer.Write(" />");
                break;

            default:
                writer.Write("<");
                writer.Write(TagName);
                AppendAttributes(writer, encoder);
                writer.Write(">");
                InnerHtml.WriteTo(writer, encoder);
                writer.Write("</");
                writer.Write(TagName);
                writer.Write(">");
                break;
            }
        }
Exemple #3
0
        /// <inheritdoc />
        public void WriteTo(TextWriter writer, IHtmlEncoder encoder)
        {
            switch (TagRenderMode)
            {
            case TagRenderMode.StartTag:
                writer.Write("<");
                writer.Write(TagName);
                AppendAttributes(writer, encoder);
                writer.Write(">");
                break;

            case TagRenderMode.EndTag:
                writer.Write("</");
                writer.Write(TagName);
                writer.Write(">");
                break;

            case TagRenderMode.SelfClosing:
                writer.Write("<");
                writer.Write(TagName);
                AppendAttributes(writer, encoder);
                writer.Write(" />");
                break;

            default:
                writer.Write("<");
                writer.Write(TagName);
                AppendAttributes(writer, encoder);
                writer.Write(">");
                InnerHtml.WriteTo(writer, encoder);
                writer.Write("</");
                writer.Write(TagName);
                writer.Write(">");
                break;
            }
        }