internal async Task WriteAsync(AsyncHtmlEncodingTextWriter writer) { if (_shouldEncode) { await writer.Write(_name).ConfigureAwait(false); if (_value != null) { await writer.WriteRaw("=\"").ConfigureAwait(false); await writer.Write(_value).ConfigureAwait(false); await writer.WriteRaw('"').ConfigureAwait(false); } } else { await writer.WriteRaw(_name).ConfigureAwait(false); if (_value != null) { await writer.WriteRaw("=\"").ConfigureAwait(false); await writer.WriteRaw(_value).ConfigureAwait(false); await writer.WriteRaw('"').ConfigureAwait(false); } } }
internal override async Task WriteAsyncImpl(AsyncHtmlEncodingTextWriter writer) { await writer.WriteRaw('<').ConfigureAwait(false); if (_shouldEncodeName) { await writer.Write(_tagName).ConfigureAwait(false); } else { await writer.WriteRaw(_tagName).ConfigureAwait(false); } foreach (var attr in _attributes) { await writer.WriteRaw(' ').ConfigureAwait(false); await attr.WriteAsync(writer).ConfigureAwait(false); } await writer.WriteRaw('>').ConfigureAwait(false); foreach (var child in _children) { await child.WriteAsyncImpl(writer).ConfigureAwait(false); } await writer.WriteRaw("</").ConfigureAwait(false); await writer.Write(_tagName).ConfigureAwait(false); await writer.WriteRaw('>').ConfigureAwait(false); }
internal override async Task WriteAsyncImpl(AsyncHtmlEncodingTextWriter writer) { foreach (var child in _children) { await child.WriteAsyncImpl(writer).ConfigureAwait(false); } }
/// <summary> /// Write the HTML to 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> /// <exception cref="InvalidOperationException">Thrown if <see cref="CanWriteAsync"/> is false (ie if this <see cref="Html"/> contains an <see cref="HtmlBuilder"/>.</exception> public async Task WriteAsync(TextWriter writer, HtmlEncoder htmlEncoder) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (htmlEncoder == null) { throw new ArgumentNullException(nameof(htmlEncoder)); } if (!CanWriteAsync) { throw new InvalidOperationException("Can't write this HTML asynchronously because it contains an HtmlBuilder"); } var htmlEncodingTextWriter = new AsyncHtmlEncodingTextWriter(writer, htmlEncoder); await WriteAsyncImpl(htmlEncodingTextWriter).ConfigureAwait(false); await htmlEncodingTextWriter.FlushAndClear().ConfigureAwait(false); }
internal override Task WriteAsyncImpl(AsyncHtmlEncodingTextWriter writer) { throw new InvalidOperationException("Can't run an HtmlBuilder asynchronously"); }
internal abstract Task WriteAsyncImpl(AsyncHtmlEncodingTextWriter writer);
internal override Task WriteAsyncImpl(AsyncHtmlEncodingTextWriter writer) => writer.Write(_text);
internal override Task WriteAsyncImpl(AsyncHtmlEncodingTextWriter writer) => writer.WriteRaw(_rawHtml);