示例#1
0
        private static IReadOnlyList <IntermediateToken> GetAttributeContent(TagHelperPropertyIntermediateNode node)
        {
            var template = node.FindDescendantNodes <TemplateIntermediateNode>().FirstOrDefault();

            if (template != null)
            {
                // See comments in TemplateDiagnosticPass
                node.Diagnostics.Add(BlazorDiagnosticFactory.CreateTemplate_InvalidLocation(template.Source));
                return(new[] { new IntermediateToken()
                               {
                                   Kind = TokenKind.CSharp, Content = string.Empty,
                               }, });
            }

            if (node.Children.Count == 1 && node.Children[0] is HtmlContentIntermediateNode htmlContentNode)
            {
                // This case can be hit for a 'string' attribute. We want to turn it into
                // an expression.
                var tokens = htmlContentNode.FindDescendantNodes <IntermediateToken>();

                var content = "\"" + string.Join(string.Empty, tokens.Select(t => t.Content)) + "\"";
                return(new[] { new IntermediateToken()
                               {
                                   Content = content, Kind = TokenKind.CSharp,
                               } });
            }
            else
            {
                return(node.FindDescendantNodes <IntermediateToken>());
            }
        }
示例#2
0
        private static IntermediateToken GetAttributeContent(TagHelperPropertyIntermediateNode node)
        {
            var template = node.FindDescendantNodes <TemplateIntermediateNode>().FirstOrDefault();

            if (template != null)
            {
                // See comments in TemplateDiagnosticPass
                node.Diagnostics.Add(ComponentDiagnosticFactory.Create_TemplateInvalidLocation(template.Source));
                return(new IntermediateToken()
                {
                    Kind = TokenKind.CSharp, Content = string.Empty,
                });
            }

            if (node.Children[0] is HtmlContentIntermediateNode htmlContentNode)
            {
                // This case can be hit for a 'string' attribute. We want to turn it into
                // an expression.
                var content = "\"" + string.Join(string.Empty, htmlContentNode.Children.OfType <IntermediateToken>().Select(t => t.Content)) + "\"";
                return(new IntermediateToken()
                {
                    Kind = TokenKind.CSharp, Content = content
                });
            }
            else if (node.Children[0] is CSharpExpressionIntermediateNode cSharpNode)
            {
                // This case can be hit when the attribute has an explicit @ inside, which
                // 'escapes' any special sugar we provide for codegen.
                return(GetToken(cSharpNode));
            }
            else
            {
                // This is the common case for 'mixed' content
                return(GetToken(node));
            }

            IntermediateToken GetToken(IntermediateNode parent)
            {
                if (parent.Children.Count == 1 && parent.Children[0] is IntermediateToken token)
                {
                    return(token);
                }

                // In error cases we won't have a single token, but we still want to generate the code.
                return(new IntermediateToken()
                {
                    Kind = TokenKind.CSharp,
                    Content = string.Join(string.Empty, parent.Children.OfType <IntermediateToken>().Select(t => t.Content)),
                });
            }
        }
示例#3
0
        private static IReadOnlyList <IntermediateToken> GetAttributeContent(TagHelperPropertyIntermediateNode node)
        {
            if (node.Children.Count == 1 && node.Children[0] is HtmlContentIntermediateNode htmlContentNode)
            {
                // This case can be hit for a 'string' attribute. We want to turn it into
                // an expression.
                var tokens = htmlContentNode.FindDescendantNodes <IntermediateToken>();

                var content = "\"" + string.Join(string.Empty, tokens.Select(t => t.Content)) + "\"";
                return(new[] { new IntermediateToken()
                               {
                                   Content = content, Kind = TokenKind.CSharp,
                               } });
            }
            else
            {
                return(node.FindDescendantNodes <IntermediateToken>());
            }
        }