Example #1
0
        /// <summary>
        /// Render the HTML into a <see cref="TextWriter"/>, using an <see cref="HtmlEncoder"/> to encode input text
        /// </summary>
        /// <param name="writer">The writer</param>
        /// <param name="htmlEncoder">The HTML encoder</param>
        public unsafe void Write(TextWriter writer, HtmlEncoder htmlEncoder)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (!_writer.IsDefault())
            {
                throw new InvalidOperationException("Write is not re-entrant");
            }

            var buffer = ArrayPool <char> .Shared.Rent(4096);

            fixed(char *start = buffer)
            {
                var htmlEncodingTextWriter = new HtmlEncodingTextWriter(writer, htmlEncoder, buffer, start, buffer.Length);

                _writer = new HtmlEncodingTextWriterReference(ref htmlEncodingTextWriter);

                try
                {
                    Build();
                    htmlEncodingTextWriter.Flush();
                }
                finally
                {
                    _writer = default;
                    ArrayPool <char> .Shared.Return(buffer);
                }
            }
        }
Example #2
0
        private void RenderAsPartial(HtmlEncodingTextWriterReference writer)
        {
            if (!_writer.IsDefault())
            {
                throw new InvalidOperationException("Write is not re-entrant");
            }

            _writer = writer;

            try
            {
                Build();
            }
            finally
            {
                _writer = default;
            }
        }