コード例 #1
0
    public ComponentAttributeIntermediateNode(TagHelperDirectiveAttributeParameterIntermediateNode directiveAttributeParameterNode)
    {
        if (directiveAttributeParameterNode == null)
        {
            throw new ArgumentNullException(nameof(directiveAttributeParameterNode));
        }

        AttributeName      = directiveAttributeParameterNode.AttributeNameWithoutParameter;
        AttributeStructure = directiveAttributeParameterNode.AttributeStructure;
        BoundAttribute     = directiveAttributeParameterNode.BoundAttribute;
        PropertyName       = directiveAttributeParameterNode.BoundAttributeParameter.GetPropertyName();
        Source             = directiveAttributeParameterNode.Source;
        TagHelper          = directiveAttributeParameterNode.TagHelper;
        TypeName           = directiveAttributeParameterNode.BoundAttributeParameter.TypeName;

        for (var i = 0; i < directiveAttributeParameterNode.Children.Count; i++)
        {
            Children.Add(directiveAttributeParameterNode.Children[i]);
        }

        for (var i = 0; i < directiveAttributeParameterNode.Diagnostics.Count; i++)
        {
            Diagnostics.Add(directiveAttributeParameterNode.Diagnostics[i]);
        }
    }
コード例 #2
0
        private IntermediateNode RewriteParameterUsage(IntermediateNode parent, TagHelperDirectiveAttributeParameterIntermediateNode node)
        {
            // Now rewrite the node to look like:
            //
            // builder.AddEventPreventDefaultAttribute(2, "onclick", true); // If minimized.
            // or
            // builder.AddEventPreventDefaultAttribute(2, "onclick", someBoolExpression); // If a bool expression is provided in the value.

            string eventHandlerMethod;

            if (node.BoundAttributeParameter.Name == "preventDefault")
            {
                eventHandlerMethod = ComponentsApi.RenderTreeBuilder.AddEventPreventDefaultAttribute;
            }
            else if (node.BoundAttributeParameter.Name == "stopPropagation")
            {
                eventHandlerMethod = ComponentsApi.RenderTreeBuilder.AddEventStopPropagationAttribute;
            }
            else
            {
                // Unsupported event handler attribute parameter. This can only happen if bound attribute descriptor
                // is configured to expect a parameter other than 'preventDefault' and 'stopPropagation'.
                return(node);
            }

            var result = new ComponentAttributeIntermediateNode(node)
            {
                Annotations =
                {
                    [ComponentMetadata.Common.OriginalAttributeName]  = node.OriginalAttributeName,
                    [ComponentMetadata.Common.AddAttributeMethodName] = eventHandlerMethod,
                },
            };

            result.Children.Clear();
            if (node.AttributeStructure != AttributeStructure.Minimized)
            {
                var tokens = GetAttributeContent(node);
                result.Children.Add(new CSharpExpressionIntermediateNode());
                result.Children[0].Children.AddRange(tokens);
            }

            return(result);
        }
コード例 #3
0
 public virtual void VisitTagHelperDirectiveAttributeParameter(TagHelperDirectiveAttributeParameterIntermediateNode node)
 {
     VisitDefault(node);
 }
コード例 #4
0
 public override void VisitTagHelperDirectiveAttributeParameter(TagHelperDirectiveAttributeParameterIntermediateNode node)
 {
     WriteContentNode(node, node.AttributeName, string.Format(CultureInfo.InvariantCulture, "HtmlAttributeValueStyle.{0}", node.AttributeStructure));
 }