コード例 #1
0
        public static async Task <TagHelperContent> ToTagHelperContentAsync(this IEnumerable <ITagHelper> tagHelpers, Options options)
        {
            var tagHelperList = tagHelpers as List <ITagHelper> ?? tagHelpers.ToList();

            if (options.Context == null)
            {
                options.Context = new TagHelperContext(new TagHelperAttributeList(), new Dictionary <object, object>(), Guid.NewGuid().ToString("N"));
            }
            if (options.Attributes == null)
            {
                options.Attributes = new List <TagHelperAttribute>();
            }
            if (options.TagName == null)
            {
                options.TagName = tagHelpers.GetTagName();
            }
            var output = new TagHelperOutput(options.TagName, new TagHelperAttributeList(options.Attributes), (b, e) => Task.Factory.StartNew(() => options.Content))
            {
                TagMode = options.TagMode
            };

            if (options.InitTagHelper)
            {
                tagHelperList.ForEach(tH => tH.Init(options.Context));
            }
            foreach (var tagHelper in tagHelperList)
            {
                await tagHelper.ProcessAsync(options.Context, output);
            }
            if (options.Content != null && !output.IsContentModified)
            {
                output.Content.SetHtmlContent(options.Content);
            }
            return(output.ToTagHelperContent());
        }
コード例 #2
0
 public static TagHelperContent Prepend(this TagHelperContent content, TagHelperOutput output) => content.Prepend(output.ToTagHelperContent());