Esempio n. 1
0
        /// <summary>
        /// Writes the specified <paramref name="value"/> with HTML encoding to given <paramref name="content"/>.
        /// </summary>
        /// <param name="content">The <see cref="TagHelperContent"/> to write to.</param>
        /// <param name="encoder">The <see cref="IHtmlEncoder"/> to use when encoding <paramref name="value"/>.</param>
        /// <param name="encoding">The character encoding in which the <paramref name="value"/> is written.</param>
        /// <param name="value">The <see cref="object"/> to write.</param>
        /// <returns><paramref name="content"/> after the write operation has completed.</returns>
        /// <remarks>
        /// <paramref name="value"/>s of type <see cref="Html.Abstractions.IHtmlContent"/> are written using
        /// <see cref="Html.Abstractions.IHtmlContent.WriteTo(System.IO.TextWriter, IHtmlEncoder)"/>.
        /// For all other types, the encoded result of <see cref="object.ToString"/>
        /// is written to the <paramref name="content"/>.
        /// </remarks>
        public static TagHelperContent Append(
            this TagHelperContent content,
            IHtmlEncoder encoder,
            Encoding encoding,
            object value)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

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

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

            using (var writer = new TagHelperContentWrapperTextWriter(encoding, content))
            {
                RazorPage.WriteTo(writer, encoder, value, escapeQuotes: true);
            }

            return(content);
        }
Esempio n. 2
0
        /// <summary>
        /// Writes the specified <paramref name="value"/> with HTML encoding to given <paramref name="content"/>.
        /// </summary>
        /// <param name="content">The <see cref="TagHelperContent"/> to write to.</param>
        /// <param name="encoder">The <see cref="IHtmlEncoder"/> to use when encoding <paramref name="value"/>.</param>
        /// <param name="encoding">The character encoding in which the <paramref name="value"/> is written.</param>
        /// <param name="value">The <see cref="object"/> to write.</param>
        /// <returns><paramref name="content"/> after the write operation has completed.</returns>
        /// <remarks>
        /// <paramref name="value"/>s of type <see cref="Rendering.HtmlString"/> are written without encoding and
        /// <see cref="HelperResult.WriteTo"/> is invoked for <see cref="HelperResult"/> types. For all other types,
        /// the encoded result of <see cref="object.ToString"/> is written to the <paramref name="content"/>.
        /// </remarks>
        public static TagHelperContent Append(
            [NotNull] this TagHelperContent content,
            [NotNull] IHtmlEncoder encoder,
            [NotNull] Encoding encoding,
            object value)
        {
            using (var writer = new TagHelperContentWrapperTextWriter(encoding, content))
            {
                RazorPage.WriteTo(writer, encoder, value, escapeQuotes: true);
            }

            return(content);
        }
Esempio n. 3
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = null;

            var partialResult = _viewEngine.FindPartialView(ViewContext, Name);

            if (partialResult != null && partialResult.Success)
            {
                var partialViewData    = new ViewDataDictionary(ViewContext.ViewData, Model);
                var partialWriter      = new TagHelperContentWrapperTextWriter(ViewContext.Writer.Encoding, output.Content);
                var partialViewContext = new ViewContext(ViewContext, partialResult.View, partialViewData, partialWriter);

                await partialResult.View.RenderAsync(partialViewContext);
            }
        }