예제 #1
0
        public static TagMode GetTagMode(
            MarkupStartTagSyntax tagBlock,
            TagHelperBinding bindingResult,
            ErrorSink errorSink)
        {
            var childSpan = tagBlock.GetLastToken()?.Parent;

            // Self-closing tags are always valid despite descriptors[X].TagStructure.
            if (childSpan?.GetContent().EndsWith("/>", StringComparison.Ordinal) ?? false)
            {
                return(TagMode.SelfClosing);
            }

            foreach (var descriptor in bindingResult.Descriptors)
            {
                var boundRules     = bindingResult.Mappings[descriptor];
                var nonDefaultRule = boundRules.FirstOrDefault(rule => rule.TagStructure != TagStructure.Unspecified);

                if (nonDefaultRule?.TagStructure == TagStructure.WithoutEndTag)
                {
                    return(TagMode.StartTagOnly);
                }
            }

            return(TagMode.StartTagAndEndTag);
        }
예제 #2
0
        public static TagMode GetTagMode(
            MarkupStartTagSyntax startTag,
            MarkupEndTagSyntax endTag,
            TagHelperBinding bindingResult)
        {
            var childSpan = startTag.GetLastToken()?.Parent;

            // Self-closing tags are always valid despite descriptors[X].TagStructure.
            if (childSpan?.GetContent().EndsWith("/>", StringComparison.Ordinal) ?? false)
            {
                return(TagMode.SelfClosing);
            }

            var hasDirectiveAttribute = false;

            foreach (var descriptor in bindingResult.Descriptors)
            {
                var boundRules     = bindingResult.Mappings[descriptor];
                var nonDefaultRule = boundRules.FirstOrDefault(rule => rule.TagStructure != TagStructure.Unspecified);

                if (nonDefaultRule?.TagStructure == TagStructure.WithoutEndTag)
                {
                    return(TagMode.StartTagOnly);
                }

                // Directive attribute will tolerate forms that don't work for tag helpers. For instance:
                //
                // <input @onclick="..."> vs <input onclick="..." />
                //
                // We don't want this to become an error just because you added a directive attribute.
                if (descriptor.IsAnyComponentDocumentTagHelper() && !descriptor.IsComponentOrChildContentTagHelper())
                {
                    hasDirectiveAttribute = true;
                }
            }

            if (hasDirectiveAttribute && startTag.IsVoidElement() && endTag == null)
            {
                return(TagMode.StartTagOnly);
            }

            return(TagMode.StartTagAndEndTag);
        }