protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) { var @namespace = documentNode.FindPrimaryNamespace(); var @class = documentNode.FindPrimaryClass(); if (@namespace == null || @class == null) { // Nothing to do, bail. We can't function without the standard structure. return; } // For each component *usage* we need to rewrite the tag helper node to map to the relevant component // APIs. var nodes = documentNode.FindDescendantNodes <TagHelperIntermediateNode>(); for (var i = 0; i < nodes.Count; i++) { var node = nodes[i]; if (node.TagHelpers.Count > 1) { node.Diagnostics.Add(BlazorDiagnosticFactory.Create_MultipleComponents(node.Source, node.TagName, node.TagHelpers)); } RewriteUsage(node, node.TagHelpers[0]); } }
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) { var @namespace = documentNode.FindPrimaryNamespace(); var @class = documentNode.FindPrimaryClass(); if (@namespace == null || @class == null) { // Nothing to do, bail. We can't function without the standard structure. return; } // For each component *usage* we need to rewrite the tag helper node to map to the relevant component // APIs. var references = documentNode.FindDescendantReferences <TagHelperIntermediateNode>(); for (var i = 0; i < references.Count; i++) { var reference = references[i]; var node = (TagHelperIntermediateNode)reference.Node; var count = 0; for (var j = 0; j < node.TagHelpers.Count; j++) { if (node.TagHelpers[j].IsComponentTagHelper()) { // Only allow a single component tag helper per element. If there are multiple, we'll just consider // the first one and ignore the others. if (count++ > 1) { node.Diagnostics.Add(BlazorDiagnosticFactory.Create_MultipleComponents(node.Source, node.TagName, node.TagHelpers)); break; } } } if (count >= 1) { reference.Replace(RewriteAsComponent(node, node.TagHelpers.First(t => t.IsComponentTagHelper()))); } else if (node.TagHelpers.Any(t => t.IsChildContentTagHelper())) { // Ignore, this will be handled when we rewrite the parent. } else { reference.Replace(RewriteAsElement(node)); } } }
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) { var @namespace = documentNode.FindPrimaryNamespace(); var @class = documentNode.FindPrimaryClass(); if (@namespace == null || @class == null) { // Nothing to do, bail. We can't function without the standard structure. return; } // For each component *usage* we need to rewrite the tag helper node to map to the relevant component // APIs. var nodes = documentNode.FindDescendantNodes <TagHelperIntermediateNode>(); for (var i = 0; i < nodes.Count; i++) { var count = 0; var node = nodes[i]; for (var j = 0; j < node.TagHelpers.Count; j++) { if (node.TagHelpers[j].IsComponentTagHelper()) { // Only allow a single component tag helper per element. We also have some *special* tag helpers // and they should have already been processed by now. if (count++ > 1) { node.Diagnostics.Add(BlazorDiagnosticFactory.Create_MultipleComponents(node.Source, node.TagName, node.TagHelpers)); break; } RewriteUsage(node, node.TagHelpers[j]); } } } }