Add Support for Templated Components (#1404)

* Test namespace cleanup

* Add recognication for RenderFragment in tag helpers

* Remove dead code from node writers

* refactor type check

* Continue to treat child content as a delegate in codegen

* Add extension to enumerate child content

* Reorganize code generation tests

These were growing a bit disorganized, and weren't really result in good
code reuse.

* fix test base class

* Add some child-content tests

* Add an explicit node for ChildContent

Adds a strongly typed node to represent a 'ChildContent' and what it
contains. This allows us to simplify the code generation path,
detect/processes more issues in IR passes, and will be essential for
supporting multiple child content.

* Ignore ChildContent in components when it's just whitespace

* Add diagnostic for duplicate child content

* Add support for explicit child content elements

Precursor to support for multiple child content items

* Add support for multiple child-content elements

* Change delegate signature for RenderFragment<T>

* Clean up Tag Helper constants

* Allow RenderFragment<T> as a child content

* Allow renaming the template parameter

* Improve error message for invalid child content

* Add diagnostic for repeated child content parameter names
This commit is contained in:
Ryan Nowak 2018-09-10 18:59:51 -07:00 committed by GitHub
parent 6546c55f4c
commit d4cbb86f46
213 changed files with 6848 additions and 3363 deletions

View File

@ -479,7 +479,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
if (template != null)
{
// See comments in TemplateDiagnosticPass
node.Diagnostics.Add(BlazorDiagnosticFactory.CreateTemplate_InvalidLocation(template.Source));
node.Diagnostics.Add(BlazorDiagnosticFactory.Create_TemplateInvalidLocation(template.Source));
return new IntermediateToken() { Kind = TokenKind.CSharp, Content = string.Empty, };
}

View File

@ -348,18 +348,23 @@ namespace Microsoft.AspNetCore.Blazor.Razor
context.RenderNode(attribute);
}
// We need to be aware of the blazor scope-tracking concept in design-time code generation
// because each component creates a lambda scope for its child content.
//
// We're hacking it a bit here by just forcing every component to have an empty lambda
_scopeStack.OpenComponentScope(node.TagName);
_scopeStack.IncrementCurrentScopeChildCount(context);
foreach (var child in node.Body)
if (node.ChildContents.Any())
{
context.RenderNode(child);
foreach (var childContent in node.ChildContents)
{
context.RenderNode(childContent);
}
}
else
{
// We eliminate 'empty' child content when building the tree so that usage like
// '<MyComponent>\r\n</MyComponent>' doesn't create a child content.
//
// Consider what would happen if the user's cursor was inside the element. At
// design -time we want to render an empty lambda to provide proper scoping
// for any code that the user types.
context.RenderNode(new ComponentChildContentIntermediateNode());
}
_scopeStack.CloseScope(context);
foreach (var capture in node.Captures)
{
@ -398,34 +403,6 @@ namespace Microsoft.AspNetCore.Blazor.Razor
{
// Do nothing
}
else if (node.Children.Count == 1 && node.Children[0] is TemplateIntermediateNode template)
{
// Templates are represented as lambdas assignable for RenderFragment<T> (for some T).
// We don't have a type to write down unless its bound to a stronly typed attribute.
// That's OK because the compiler gives an error if we can't type check it.
context.CodeWriter.Write(DesignTimeVariable);
context.CodeWriter.Write(" = ");
// If we have a parameter type, then add a type check.
if (NeedsTypeCheck(node))
{
context.CodeWriter.Write(BlazorApi.RuntimeHelpers.TypeCheck);
context.CodeWriter.Write("<");
context.CodeWriter.Write(node.BoundAttribute.TypeName);
context.CodeWriter.Write(">");
context.CodeWriter.Write("(");
}
context.RenderNode(template);
if (NeedsTypeCheck(node))
{
context.CodeWriter.Write(")");
}
context.CodeWriter.Write(";");
context.CodeWriter.WriteLine();
}
else
{
// There are a few different forms that could be used to contain all of the tokens, but we don't really care
@ -440,7 +417,8 @@ namespace Microsoft.AspNetCore.Blazor.Razor
// Of a list of tokens directly in the attribute.
var tokens = GetCSharpTokens(node);
if (node.BoundAttribute?.IsDelegateProperty() ?? false)
if ((node.BoundAttribute?.IsDelegateProperty() ?? false) ||
(node.BoundAttribute?.IsChildContentProperty() ?? false))
{
// We always surround the expression with the delegate constructor. This makes type
// inference inside lambdas, and method group conversion do the right thing.
@ -502,6 +480,30 @@ namespace Microsoft.AspNetCore.Blazor.Razor
}
}
public override void WriteComponentChildContent(CodeRenderingContext context, ComponentChildContentIntermediateNode node)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (node == null)
{
throw new ArgumentNullException(nameof(node));
}
_scopeStack.OpenComponentScope(
context,
node.AttributeName,
node.TypeName,
node.IsParameterized ? node.ParameterName : null);
for (var i = 0; i < node.Children.Count; i++)
{
context.RenderNode(node.Children[i]);
}
_scopeStack.CloseScope(context);
}
public override void WriteTemplate(CodeRenderingContext context, TemplateIntermediateNode node)
{
if (context == null)
@ -514,11 +516,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
throw new ArgumentNullException(nameof(node));
}
// Since the user doesn't write this name themselves, we have to use something hardcoded
// and predicatable.
const string VariableName = "context";
_scopeStack.OpenTemplateScope(context, VariableName);
_scopeStack.OpenTemplateScope(context);
context.RenderChildren(node);
_scopeStack.CloseScope(context);
}

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Razor.Language;
@ -178,15 +179,89 @@ namespace Microsoft.AspNetCore.Blazor.Razor
return diagnostic;
}
public static readonly RazorDiagnosticDescriptor Template_InvalidLocation =
public static readonly RazorDiagnosticDescriptor TemplateInvalidLocation =
new RazorDiagnosticDescriptor(
"BL9994",
() => "Razor templates cannot be used in attributes.",
RazorDiagnosticSeverity.Error);
public static RazorDiagnostic CreateTemplate_InvalidLocation(SourceSpan? source)
public static RazorDiagnostic Create_TemplateInvalidLocation(SourceSpan? source)
{
return RazorDiagnostic.Create(Template_InvalidLocation, source ?? SourceSpan.Undefined);
return RazorDiagnostic.Create(TemplateInvalidLocation, source ?? SourceSpan.Undefined);
}
public static readonly RazorDiagnosticDescriptor ChildContentSetByAttributeAndBody =
new RazorDiagnosticDescriptor(
"BL9995",
() => "The child content property '{0}' is set by both the attribute and the element contents.",
RazorDiagnosticSeverity.Error);
public static RazorDiagnostic Create_ChildContentSetByAttributeAndBody(SourceSpan? source, string attribute)
{
return RazorDiagnostic.Create(ChildContentSetByAttributeAndBody, source ?? SourceSpan.Undefined, attribute);
}
public static readonly RazorDiagnosticDescriptor ChildContentMixedWithExplicitChildContent =
new RazorDiagnosticDescriptor(
"BL9996",
() => "Unrecognized child content inside component '{0}'. The component '{0}' accepts child content through the " +
"following top-level items: {1}.",
RazorDiagnosticSeverity.Error);
public static RazorDiagnostic Create_ChildContentMixedWithExplicitChildContent(SourceSpan? source, ComponentExtensionNode component)
{
var supportedElements = string.Join(", ", component.Component.GetChildContentProperties().Select(p => $"'{p.Name}'"));
return RazorDiagnostic.Create(ChildContentMixedWithExplicitChildContent, source ?? SourceSpan.Undefined, component.TagName, supportedElements);
}
public static readonly RazorDiagnosticDescriptor ChildContentHasInvalidAttribute =
new RazorDiagnosticDescriptor(
"BL9997",
() => "Unrecognized attribute '{0}' on child content element '{1}'.",
RazorDiagnosticSeverity.Error);
public static RazorDiagnostic Create_ChildContentHasInvalidAttribute(SourceSpan? source, string attribute, string element)
{
return RazorDiagnostic.Create(ChildContentHasInvalidAttribute, source ?? SourceSpan.Undefined, attribute, element);
}
public static readonly RazorDiagnosticDescriptor ChildContentHasInvalidParameter =
new RazorDiagnosticDescriptor(
"BL9998",
() => "Invalid parameter name. The parameter name attribute '{0}' on child content element '{1}' can only include literal text.",
RazorDiagnosticSeverity.Error);
public static RazorDiagnostic Create_ChildContentHasInvalidParameter(SourceSpan? source, string attribute, string element)
{
return RazorDiagnostic.Create(ChildContentHasInvalidParameter, source ?? SourceSpan.Undefined, attribute, element);
}
public static readonly RazorDiagnosticDescriptor ChildContentRepeatedParameterName =
new RazorDiagnosticDescriptor(
"BL9999",
() => "The child content element '{0}' of component '{1}' uses the same parameter name ('{2}') as enclosing child content " +
"element '{3}' of component '{4}'. Specify the parameter name like: '<{0} Context=\"another_name\"> to resolve the ambiguity",
RazorDiagnosticSeverity.Error);
public static RazorDiagnostic Create_ChildContentRepeatedParameterName(
SourceSpan? source,
ComponentChildContentIntermediateNode childContent1,
ComponentExtensionNode component1,
ComponentChildContentIntermediateNode childContent2,
ComponentExtensionNode component2)
{
Debug.Assert(childContent1.ParameterName == childContent2.ParameterName);
Debug.Assert(childContent1.IsParameterized);
Debug.Assert(childContent2.IsParameterized);
return RazorDiagnostic.Create(
ChildContentRepeatedParameterName,
source ?? SourceSpan.Undefined,
childContent1.AttributeName,
component1.TagName,
childContent1.ParameterName,
childContent2.AttributeName,
component2.TagName);
}
}
}

View File

@ -82,6 +82,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
builder.Features.Add(new RefLoweringPass());
builder.Features.Add(new BindLoweringPass());
builder.Features.Add(new TemplateDiagnosticPass());
builder.Features.Add(new ChildContentDiagnosticPass());
builder.Features.Add(new HtmlBlockPass());
builder.Features.Add(new ComponentTagHelperDescriptorProvider());

View File

@ -26,8 +26,19 @@ namespace Microsoft.AspNetCore.Blazor.Razor
public readonly static string ChangeAttribute = "Blazor.Bind.ChangeAttribute";
}
public static class ChildContent
{
public static readonly string RuntimeName = "Blazor.None";
public static readonly string TagHelperKind = "Blazor.ChildContent";
public static readonly string ParameterNameBoundAttributeKind = "Blazor.ChildContentParameterName";
}
public static class Component
{
public static readonly string ChildContentKey = "Blazor.ChildContent";
public static readonly string DelegateSignatureKey = "Blazor.DelegateSignature";
public static readonly string WeaklyTypedKey = "Blazor.IsWeaklyTyped";

View File

@ -17,6 +17,8 @@ namespace Microsoft.AspNetCore.Blazor.Razor
public abstract void WriteComponentAttribute(CodeRenderingContext context, ComponentAttributeExtensionNode node);
public abstract void WriteComponentChildContent(CodeRenderingContext context, ComponentChildContentIntermediateNode node);
public abstract void WriteHtmlElement(CodeRenderingContext context, HtmlElementIntermediateNode node);
public abstract void WriteHtmlBlock(CodeRenderingContext context, HtmlBlockIntermediateNode node);

View File

@ -65,7 +65,6 @@ namespace Microsoft.AspNetCore.Blazor.Razor
{
if (node.Children[i] is IntermediateToken token && token.IsCSharp)
{
_scopeStack.IncrementCurrentScopeChildCount(context);
context.AddSourceMappingFor(token);
context.CodeWriter.Write(token.Content);
}
@ -100,7 +99,6 @@ namespace Microsoft.AspNetCore.Blazor.Razor
// Since we're not in the middle of writing an element, this must evaluate as some
// text to display
_scopeStack.IncrementCurrentScopeChildCount(context);
context.CodeWriter
.WriteStartMethodInvocation($"{_scopeStack.BuilderVarName}.{nameof(BlazorApi.RenderTreeBuilder.AddContent)}")
.Write((_sourceSequence++).ToString())
@ -161,8 +159,6 @@ namespace Microsoft.AspNetCore.Blazor.Razor
throw new ArgumentNullException(nameof(node));
}
_scopeStack.IncrementCurrentScopeChildCount(context);
context.CodeWriter
.WriteStartMethodInvocation($"{_scopeStack.BuilderVarName}.{nameof(BlazorApi.RenderTreeBuilder.AddMarkupContent)}")
.Write((_sourceSequence++).ToString())
@ -183,8 +179,6 @@ namespace Microsoft.AspNetCore.Blazor.Razor
throw new ArgumentNullException(nameof(node));
}
_scopeStack.IncrementCurrentScopeChildCount(context);
context.CodeWriter
.WriteStartMethodInvocation($"{_scopeStack.BuilderVarName}.{nameof(BlazorApi.RenderTreeBuilder.OpenElement)}")
.Write((_sourceSequence++).ToString())
@ -267,7 +261,6 @@ namespace Microsoft.AspNetCore.Blazor.Razor
// Text node
var content = GetHtmlContent(node);
_scopeStack.IncrementCurrentScopeChildCount(context);
context.CodeWriter
.WriteStartMethodInvocation($"{_scopeStack.BuilderVarName}.{nameof(BlazorApi.RenderTreeBuilder.AddContent)}")
.Write((_sourceSequence++).ToString())
@ -303,9 +296,6 @@ namespace Microsoft.AspNetCore.Blazor.Razor
throw new ArgumentNullException(nameof(node));
}
// The start tag counts as a child from a markup point of view.
_scopeStack.IncrementCurrentScopeChildCount(context);
// builder.OpenComponent<TComponent>(42);
context.CodeWriter.Write(_scopeStack.BuilderVarName);
context.CodeWriter.Write(".");
@ -321,22 +311,17 @@ namespace Microsoft.AspNetCore.Blazor.Razor
{
context.RenderNode(attribute);
}
_scopeStack.OpenComponentScope(node.TagName);
foreach (var child in node.Body)
foreach (var childContent in node.ChildContents)
{
context.RenderNode(child);
context.RenderNode(childContent);
}
_scopeStack.CloseScope(context);
foreach (var capture in node.Captures)
{
context.RenderNode(capture);
}
// The close tag counts as a child from a markup point of view.
_scopeStack.IncrementCurrentScopeChildCount(context);
// builder.OpenComponent<TComponent>(42);
context.CodeWriter.Write(_scopeStack.BuilderVarName);
context.CodeWriter.Write(".");
@ -383,34 +368,12 @@ namespace Microsoft.AspNetCore.Blazor.Razor
var content = string.Join(string.Empty, GetHtmlTokens(htmlNode).Select(t => t.Content));
context.CodeWriter.WriteStringLiteral(content);
}
else if (node.Children.Count == 1 && node.Children[0] is TemplateIntermediateNode template)
{
// Templates are represented as lambdas assignable for RenderFragment<T> (for some T).
// We don't have a type to write down unless its bound to a stronly typed attribute.
// That's OK because the compiler gives an error if we can't type check it.
// If we have a parameter type, then add a type check.
if (node.BoundAttribute != null && !node.BoundAttribute.IsWeaklyTyped())
{
context.CodeWriter.Write(BlazorApi.RuntimeHelpers.TypeCheck);
context.CodeWriter.Write("<");
context.CodeWriter.Write(node.BoundAttribute.TypeName);
context.CodeWriter.Write(">");
context.CodeWriter.Write("(");
}
context.RenderNode(template);
if (node.BoundAttribute != null && !node.BoundAttribute.IsWeaklyTyped())
{
context.CodeWriter.Write(")");
}
}
else
{
// See comments in BlazorDesignTimeNodeWriter for a description of the cases that are possible.
var tokens = GetCSharpTokens(node);
if (node.BoundAttribute?.IsDelegateProperty() ?? false)
if ((node.BoundAttribute?.IsDelegateProperty() ?? false) ||
(node.BoundAttribute?.IsChildContentProperty() ?? false))
{
context.CodeWriter.Write("new ");
context.CodeWriter.Write(node.BoundAttribute.TypeName);
@ -425,7 +388,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
}
else
{
if (node.BoundAttribute != null && !node.BoundAttribute.IsWeaklyTyped())
if (NeedsTypeCheck(node))
{
context.CodeWriter.Write(BlazorApi.RuntimeHelpers.TypeCheck);
context.CodeWriter.Write("<");
@ -439,7 +402,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
context.CodeWriter.Write(tokens[i].Content);
}
if (node.BoundAttribute != null && !node.BoundAttribute.IsWeaklyTyped())
if (NeedsTypeCheck(node))
{
context.CodeWriter.Write(")");
}
@ -460,6 +423,35 @@ namespace Microsoft.AspNetCore.Blazor.Razor
// We generally expect all children to be HTML, this is here just in case.
return html.FindDescendantNodes<IntermediateToken>().Where(t => t.IsHtml).ToArray();
}
bool NeedsTypeCheck(ComponentAttributeExtensionNode n)
{
return node.BoundAttribute != null && !node.BoundAttribute.IsWeaklyTyped();
}
}
public override void WriteComponentChildContent(CodeRenderingContext context, ComponentChildContentIntermediateNode node)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (node == null)
{
throw new ArgumentNullException(nameof(node));
}
_scopeStack.OpenComponentScope(
context,
node.AttributeName,
node.TypeName,
node.IsParameterized ? node.ParameterName : null);
for (var i = 0; i < node.Children.Count; i++)
{
context.RenderNode(node.Children[i]);
}
_scopeStack.CloseScope(context);
}
public override void WriteTemplate(CodeRenderingContext context, TemplateIntermediateNode node)
@ -474,11 +466,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
throw new ArgumentNullException(nameof(node));
}
// Since the user doesn't write this name themselves, we have to use something hardcoded
// and predicatable.
const string VariableName = "context";
_scopeStack.OpenTemplateScope(context, VariableName);
_scopeStack.OpenTemplateScope(context);
context.RenderChildren(node);
_scopeStack.CloseScope(context);
}

View File

@ -0,0 +1,72 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
namespace Microsoft.AspNetCore.Blazor.Razor
{
internal class ChildContentDiagnosticPass : IntermediateNodePassBase, IRazorOptimizationPass
{
// Runs after components/eventhandlers/ref/bind/templates. We want to validate every component
// and it's usage of ChildContent.
public override int Order => 160;
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{
var visitor = new Visitor();
visitor.Visit(documentNode);
}
private class Visitor : IntermediateNodeWalker, IExtensionIntermediateNodeVisitor<ComponentExtensionNode>, IExtensionIntermediateNodeVisitor<ComponentChildContentIntermediateNode>
{
public void VisitExtension(ComponentExtensionNode node)
{
// Check for properties that are set by both element contents (body) and the attribute itself.
foreach (var childContent in node.ChildContents)
{
foreach (var attribute in node.Attributes)
{
if (attribute.AttributeName == childContent.AttributeName)
{
node.Diagnostics.Add(BlazorDiagnosticFactory.Create_ChildContentSetByAttributeAndBody(
attribute.Source,
attribute.AttributeName));
}
}
}
base.VisitDefault(node);
}
public void VisitExtension(ComponentChildContentIntermediateNode node)
{
// Check that each child content has a unique parameter name within its scope. This is important
// because the parameter name can be implict, and it doesn't work well when nested.
if (node.IsParameterized)
{
for (var i = 0; i < Ancestors.Count - 1; i++)
{
var ancestor = Ancestors[i] as ComponentChildContentIntermediateNode;
if (ancestor != null &&
ancestor.IsParameterized &&
string.Equals(node.ParameterName, ancestor.ParameterName, StringComparison.Ordinal))
{
// Duplicate name. We report an error because this will almost certainly also lead to an error
// from the C# compiler that's way less clear.
node.Diagnostics.Add(BlazorDiagnosticFactory.Create_ChildContentRepeatedParameterName(
node.Source,
node,
(ComponentExtensionNode)Ancestors[0], // Encosing component
ancestor, // conflicting child content node
(ComponentExtensionNode)Ancestors[i + 1])); // Encosing component of conflicting child content node
}
}
}
base.VisitDefault(node);
}
}
}
}

View File

@ -0,0 +1,52 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Blazor.Shared;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.CodeGeneration;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
namespace Microsoft.AspNetCore.Blazor.Razor
{
internal class ComponentChildContentIntermediateNode : ExtensionIntermediateNode
{
public string AttributeName => BoundAttribute?.Name ?? BlazorApi.RenderTreeBuilder.ChildContent;
public BoundAttributeDescriptor BoundAttribute { get; set; }
public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection();
public bool IsParameterized => BoundAttribute?.IsParameterizedChildContentProperty() ?? false;
public string ParameterName { get; set; } = "context";
public string TypeName => BoundAttribute?.TypeName == null ? BlazorApi.RenderFragment.FullTypeName : BoundAttribute.TypeName;
public override void Accept(IntermediateNodeVisitor visitor)
{
if (visitor == null)
{
throw new ArgumentNullException(nameof(visitor));
}
AcceptExtensionNode<ComponentChildContentIntermediateNode>(this, visitor);
}
public override void WriteNode(CodeTarget target, CodeRenderingContext context)
{
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var writer = (BlazorNodeWriter)context.NodeWriter;
writer.WriteComponentChildContent(context, this);
}
}
}

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -17,12 +17,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
public IEnumerable<RefExtensionNode> Captures => Children.OfType<RefExtensionNode>();
public IEnumerable<IntermediateNode> Body => Children.Where(c =>
{
return
c as ComponentAttributeExtensionNode == null &&
c as RefExtensionNode == null;
});
public IEnumerable<ComponentChildContentIntermediateNode> ChildContents => Children.OfType<ComponentChildContentIntermediateNode>();
public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection();
@ -82,7 +77,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
}
builder.Append(">");
builder.Append(Body.Any() ? "..." : string.Empty);
builder.Append(ChildContents.Any() ? "..." : string.Empty);
builder.Append("</");
builder.Append(TagName);
builder.Append(">");

View File

@ -1,7 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.Linq;
using Microsoft.AspNetCore.Blazor.Shared;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
@ -49,6 +52,10 @@ namespace Microsoft.AspNetCore.Blazor.Razor
{
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));
@ -58,7 +65,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
private ComponentExtensionNode RewriteAsComponent(TagHelperIntermediateNode node, TagHelperDescriptor tagHelper)
{
var result = new ComponentExtensionNode()
var component = new ComponentExtensionNode()
{
Component = tagHelper,
Source = node.Source,
@ -67,13 +74,13 @@ namespace Microsoft.AspNetCore.Blazor.Razor
for (var i = 0; i < node.Diagnostics.Count; i++)
{
result.Diagnostics.Add(node.Diagnostics[i]);
component.Diagnostics.Add(node.Diagnostics[i]);
}
var visitor = new ComponentRewriteVisitor(result.Children);
var visitor = new ComponentRewriteVisitor(component);
visitor.Visit(node);
return result;
return component;
}
private HtmlElementIntermediateNode RewriteAsElement(TagHelperIntermediateNode node)
@ -97,28 +104,182 @@ namespace Microsoft.AspNetCore.Blazor.Razor
private class ComponentRewriteVisitor : IntermediateNodeWalker
{
private readonly ComponentExtensionNode _component;
private readonly IntermediateNodeCollection _children;
public ComponentRewriteVisitor(IntermediateNodeCollection children)
public ComponentRewriteVisitor(ComponentExtensionNode component)
{
_children = children;
_component = component;
_children = component.Children;
}
public override void VisitTagHelper(TagHelperIntermediateNode node)
{
// Visit children, we're replacing this node.
for (var i = 0; i < node.Children.Count; i++)
{
Visit(node.Children[i]);
}
base.VisitDefault(node);
}
public override void VisitTagHelperBody(TagHelperBodyIntermediateNode node)
{
// Wrap the component's children in a ChildContent node if we have some significant
// content.
if (node.Children.Count == 0)
{
return;
}
// If we get a single HTML content node containing only whitespace,
// then this is probably a tag that looks like '<MyComponent> </MyComponent>
//
// We don't want to create a child content for this case, because it can conflict
// with a child content that's set via an attribute. We don't want the formatting
// of insigificant whitespace to be annoying when setting attributes directly.
if (node.Children.Count == 1 && IsIgnorableWhitespace(node.Children[0]))
{
return;
}
// From here we fork and behave differently based on whether the component's child content is
// implicit or explicit.
//
// Explict child content will look like: <MyComponent><ChildContent><div>...</div></ChildContent></MyComponent>
// compared with implicit: <MyComponent><div></div></MyComponent>
//
// Using implicit child content:
// 1. All content is grouped into a single child content lambda, and assiged to the property 'ChildContent'
//
// Using explicit child content:
// 1. All content must be contained within 'child content' elements that are direct children
// 2. Whitespace outside of 'child content' elements will be ignored (not an error)
// 3. Non-whitespace outside of 'child content' elements will cause an error
// 4. All 'child content' elements must match parameters on the component (exception for ChildContent,
// which is always allowed.
// 5. Each 'child content' element will generate its own lambda, and be assigned to the property
// that matches the element name.
if (!node.Children.OfType<TagHelperIntermediateNode>().Any(t => t.TagHelpers.Any(th => th.IsChildContentTagHelper())))
{
// This node has implicit child content. It may or may not have an attribute that matches.
var attribute = _component.Component.BoundAttributes
.Where(a => string.Equals(a.Name, BlazorApi.RenderTreeBuilder.ChildContent, StringComparison.Ordinal))
.FirstOrDefault();
_children.Add(RewriteChildContent(attribute, node.Source, node.Children));
return;
}
// OK this node has explicit child content, we can rewrite it by visiting each node
// in sequence, since we:
// a) need to rewrite each child content element
// b) any significant content outside of a child content is an error
for (var i = 0; i < node.Children.Count; i++)
{
_children.Add(node.Children[i]);
var child = node.Children[i];
if (IsIgnorableWhitespace(child))
{
continue;
}
if (child is TagHelperIntermediateNode tagHelperNode &&
tagHelperNode.TagHelpers.Any(th => th.IsChildContentTagHelper()))
{
// This is a child content element
var attribute = _component.Component.BoundAttributes
.Where(a => string.Equals(a.Name, tagHelperNode.TagName, StringComparison.Ordinal))
.FirstOrDefault();
_children.Add(RewriteChildContent(attribute, child.Source, child.Children));
continue;
}
// If we get here then this is significant content inside a component with explicit child content.
child.Diagnostics.Add(BlazorDiagnosticFactory.Create_ChildContentMixedWithExplicitChildContent(child.Source, _component));
_children.Add(child);
}
bool IsIgnorableWhitespace(IntermediateNode n)
{
if (n is HtmlContentIntermediateNode html &&
html.Children.Count == 1 &&
html.Children[0] is IntermediateToken token &&
string.IsNullOrWhiteSpace(token.Content))
{
return true;
}
return false;
}
}
private ComponentChildContentIntermediateNode RewriteChildContent(BoundAttributeDescriptor attribute, SourceSpan? source, IntermediateNodeCollection children)
{
var childContent = new ComponentChildContentIntermediateNode()
{
BoundAttribute = attribute,
Source = source,
};
// There are two cases here:
// 1. Implicit child content - the children will be non-taghelper nodes, just accept them
// 2. Explicit child content - the children will be various tag helper nodes, that need special processing.
for (var i = 0; i < children.Count; i++)
{
var child = children[i];
if (child is TagHelperBodyIntermediateNode body)
{
// The body is all of the content we want to render, the rest of the childen will
// be the attributes.
for (var j = 0; j < body.Children.Count; j++)
{
childContent.Children.Add(body.Children[j]);
}
}
else if (child is TagHelperPropertyIntermediateNode property)
{
if (property.BoundAttribute.Kind == BlazorMetadata.ChildContent.TagHelperKind)
{
// Check for each child content with a parameter name, that the parameter name is specified
// with literal text. For instance, the following is not allowed and should generate a diagnostic.
//
// <MyComponent><ChildContent Context="@Foo()">...</ChildContent></MyComponent>
if (TryGetAttributeStringContent(property, out var parameterName))
{
childContent.ParameterName = parameterName;
continue;
}
// The parameter name is invalid.
childContent.Diagnostics.Add(BlazorDiagnosticFactory.Create_ChildContentHasInvalidParameter(property.Source, property.AttributeName, attribute.Name));
continue;
}
// This is an unrecognized attribute, this is possible if you try to do something like put 'ref' on a child content.
childContent.Diagnostics.Add(BlazorDiagnosticFactory.Create_ChildContentHasInvalidAttribute(property.Source, property.AttributeName, attribute.Name));
}
else if (child is TagHelperHtmlAttributeIntermediateNode a)
{
// This is an HTML attribute on a child content.
childContent.Diagnostics.Add(BlazorDiagnosticFactory.Create_ChildContentHasInvalidAttribute(a.Source, a.AttributeName, attribute.Name));
}
else
{
// This is some other kind of node (likely an implicit child content)
childContent.Children.Add(child);
}
}
return childContent;
}
private bool TryGetAttributeStringContent(TagHelperPropertyIntermediateNode property, out string content)
{
// The success path looks like - a single HTML Attribute Value node with tokens
if (property.Children.Count == 1 &&
property.Children[0] is HtmlContentIntermediateNode html)
{
content = string.Join(string.Empty, html.Children.OfType<IntermediateToken>().Select(n => n.Content));
return true;
}
content = null;
return false;
}
public override void VisitTagHelperHtmlAttribute(TagHelperHtmlAttributeIntermediateNode node)

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -45,29 +45,10 @@ namespace Microsoft.AspNetCore.Blazor.Razor
// We need to see private members too
compilation = WithMetadataImportOptionsAll(compilation);
var componentSymbol = compilation.GetTypeByMetadataName(BlazorApi.IComponent.MetadataName);
if (componentSymbol == null)
{
// No definition for IComponent, nothing to do.
return;
}
var parameterSymbol = compilation.GetTypeByMetadataName(BlazorApi.ParameterAttribute.FullTypeName);
if (parameterSymbol == null)
{
// No definition for [Parameter], nothing to do.
return;
}
var blazorComponentSymbol = compilation.GetTypeByMetadataName(BlazorApi.BlazorComponent.FullTypeName);
if (blazorComponentSymbol == null)
{
// No definition for BlazorComponent, nothing to do.
return;
}
var symbols = BlazorSymbols.Create(compilation);
var types = new List<INamedTypeSymbol>();
var visitor = new ComponentTypeVisitor(componentSymbol, types);
var visitor = new ComponentTypeVisitor(symbols, types);
// Visit the primary output of this compilation, as well as all references.
visitor.Visit(compilation.Assembly);
@ -84,7 +65,14 @@ namespace Microsoft.AspNetCore.Blazor.Razor
for (var i = 0; i < types.Count; i++)
{
var type = types[i];
context.Results.Add(CreateDescriptor(type, parameterSymbol, blazorComponentSymbol));
var descriptor = CreateDescriptor(symbols, type);
context.Results.Add(descriptor);
foreach (var childContent in descriptor.GetChildContentProperties())
{
// Synthesize a separate tag helper for each child content property that's declared.
context.Results.Add(CreateChildContentDescriptor(symbols, descriptor, childContent));
}
}
}
@ -95,18 +83,8 @@ namespace Microsoft.AspNetCore.Blazor.Razor
return compilation.WithOptions(newCompilationOptions);
}
private TagHelperDescriptor CreateDescriptor(INamedTypeSymbol type, INamedTypeSymbol parameterSymbol, INamedTypeSymbol blazorComponentSymbol)
private TagHelperDescriptor CreateDescriptor(BlazorSymbols symbols, INamedTypeSymbol type)
{
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}
if (parameterSymbol == null)
{
throw new ArgumentNullException(nameof(parameterSymbol));
}
var typeName = type.ToDisplayString(FullNameTypeDisplayFormat);
var assemblyName = type.ContainingAssembly.Identity.Name;
@ -126,7 +104,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
// Components have very simple matching rules. The type name (short) matches the tag name.
builder.TagMatchingRule(r => r.TagName = type.Name);
foreach (var property in GetProperties(type, parameterSymbol, blazorComponentSymbol))
foreach (var property in GetProperties(symbols, type))
{
if (property.kind == PropertyKind.Ignored)
{
@ -144,6 +122,11 @@ namespace Microsoft.AspNetCore.Blazor.Razor
pb.IsEnum = true;
}
if (property.kind == PropertyKind.ChildContent)
{
pb.Metadata.Add(BlazorMetadata.Component.ChildContentKey, bool.TrueString);
}
if (property.kind == PropertyKind.Delegate)
{
pb.Metadata.Add(BlazorMetadata.Component.DelegateSignatureKey, bool.TrueString);
@ -162,6 +145,51 @@ namespace Microsoft.AspNetCore.Blazor.Razor
return descriptor;
}
private TagHelperDescriptor CreateChildContentDescriptor(BlazorSymbols symbols, TagHelperDescriptor component, BoundAttributeDescriptor attribute)
{
var typeName = component.GetTypeName() + "." + attribute.Name;
var assemblyName = component.AssemblyName;
var builder = TagHelperDescriptorBuilder.Create(BlazorMetadata.ChildContent.TagHelperKind, typeName, assemblyName);
builder.SetTypeName(typeName);
// This opts out this 'component' tag helper for any processing that's specific to the default
// Razor ITagHelper runtime.
builder.Metadata[TagHelperMetadata.Runtime.Name] = BlazorMetadata.ChildContent.RuntimeName;
// Opt out of processing as a component. We'll process this specially as part of the component's body.
builder.Metadata[BlazorMetadata.SpecialKindKey] = BlazorMetadata.ChildContent.TagHelperKind;
var xml = attribute.Documentation;
if (!string.IsNullOrEmpty(xml))
{
builder.Documentation = xml;
}
// Child content matches the property name, but only as a direct child of the component.
builder.TagMatchingRule(r =>
{
r.TagName = attribute.Name;
r.ParentTag = component.TagMatchingRules.First().TagName;
});
if (attribute.IsParameterizedChildContentProperty())
{
// For child content attributes with a parameter, synthesize an attribute that allows you to name
// the parameter.
builder.BindAttribute(b =>
{
b.Name = "Context";
b.TypeName = typeof(string).FullName;
b.Documentation = string.Format(Resources.ChildContentParameterName_Documentation, attribute.Name);
});
}
var descriptor = builder.Build();
return descriptor;
}
// Does a walk up the inheritance chain to determine the set of parameters by using
// a dictionary keyed on property name.
//
@ -170,12 +198,12 @@ namespace Microsoft.AspNetCore.Blazor.Razor
// - have the [Parameter] attribute
// - have a setter, even if private
// - are not indexers
private IEnumerable<(IPropertySymbol property, PropertyKind kind)> GetProperties(INamedTypeSymbol type, INamedTypeSymbol parameterSymbol, INamedTypeSymbol blazorComponentSymbol)
private IEnumerable<(IPropertySymbol property, PropertyKind kind)> GetProperties(BlazorSymbols symbols, INamedTypeSymbol type)
{
var properties = new Dictionary<string, (IPropertySymbol, PropertyKind)>(StringComparer.Ordinal);
do
{
if (type == blazorComponentSymbol)
if (type == symbols.BlazorComponent)
{
// The BlazorComponent base class doesn't have any [Parameter].
// Bail out now to avoid walking through its many members, plus the members
@ -217,7 +245,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
kind = PropertyKind.Ignored;
}
if (!property.GetAttributes().Any(a => a.AttributeClass == parameterSymbol))
if (!property.GetAttributes().Any(a => a.AttributeClass == symbols.ParameterAttribute))
{
// Does not have [Parameter]
kind = PropertyKind.Ignored;
@ -228,6 +256,19 @@ namespace Microsoft.AspNetCore.Blazor.Razor
kind = PropertyKind.Enum;
}
if (kind == PropertyKind.Default && property.Type == symbols.RenderFragment)
{
kind = PropertyKind.ChildContent;
}
if (kind == PropertyKind.Default &&
property.Type is INamedTypeSymbol namedType &&
namedType.IsGenericType &&
namedType.ConstructedFrom == symbols.RenderFragmentOfT)
{
kind = PropertyKind.ChildContent;
}
if (kind == PropertyKind.Default && property.Type.TypeKind == TypeKind.Delegate)
{
kind = PropertyKind.Delegate;
@ -248,17 +289,74 @@ namespace Microsoft.AspNetCore.Blazor.Razor
Ignored,
Default,
Enum,
ChildContent,
Delegate,
}
private class BlazorSymbols
{
public static BlazorSymbols Create(Compilation compilation)
{
var symbols = new BlazorSymbols();
symbols.BlazorComponent = compilation.GetTypeByMetadataName(BlazorApi.BlazorComponent.MetadataName);
if (symbols.BlazorComponent == null)
{
// No definition for BlazorComponent, nothing to do.
return null;
}
symbols.IComponent = compilation.GetTypeByMetadataName(BlazorApi.IComponent.MetadataName);
if (symbols.IComponent == null)
{
// No definition for IComponent, nothing to do.
return null;
}
symbols.ParameterAttribute = compilation.GetTypeByMetadataName(BlazorApi.ParameterAttribute.MetadataName);
if (symbols.ParameterAttribute == null)
{
// No definition for [Parameter], nothing to do.
return null;
}
symbols.RenderFragment = compilation.GetTypeByMetadataName(BlazorApi.RenderFragment.MetadataName);
if (symbols.RenderFragment == null)
{
// No definition for RenderFragment, nothing to do.
}
symbols.RenderFragmentOfT = compilation.GetTypeByMetadataName(BlazorApi.RenderFragmentOfT.MetadataName);
if (symbols.RenderFragmentOfT == null)
{
// No definition for RenderFragment, nothing to do.
}
return symbols;
}
private BlazorSymbols()
{
}
public INamedTypeSymbol BlazorComponent { get; private set; }
public INamedTypeSymbol IComponent { get; private set; }
public INamedTypeSymbol ParameterAttribute { get; private set; }
public INamedTypeSymbol RenderFragment { get; private set; }
public INamedTypeSymbol RenderFragmentOfT { get; private set; }
}
private class ComponentTypeVisitor : SymbolVisitor
{
private INamedTypeSymbol _interface;
private List<INamedTypeSymbol> _results;
private readonly BlazorSymbols _symbols;
private readonly List<INamedTypeSymbol> _results;
public ComponentTypeVisitor(INamedTypeSymbol @interface, List<INamedTypeSymbol> results)
public ComponentTypeVisitor(BlazorSymbols symbols, List<INamedTypeSymbol> results)
{
_interface = @interface;
_symbols = symbols;
_results = results;
}
@ -290,7 +388,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
internal bool IsComponent(INamedTypeSymbol symbol)
{
if (_interface == null)
if (_symbols == null)
{
return false;
}
@ -299,7 +397,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
symbol.DeclaredAccessibility == Accessibility.Public &&
!symbol.IsAbstract &&
!symbol.IsGenericType &&
symbol.AllInterfaces.Contains(_interface);
symbol.AllInterfaces.Contains(_symbols.IComponent);
}
}
}

View File

@ -189,7 +189,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
if (template != null)
{
// See comments in TemplateDiagnosticPass
node.Diagnostics.Add(BlazorDiagnosticFactory.CreateTemplate_InvalidLocation(template.Source));
node.Diagnostics.Add(BlazorDiagnosticFactory.Create_TemplateInvalidLocation(template.Source));
return new[] { new IntermediateToken() { Kind = TokenKind.CSharp, Content = string.Empty, }, };
}

View File

@ -105,6 +105,15 @@ namespace Microsoft.AspNetCore.Blazor.Razor {
}
}
/// <summary>
/// Looks up a localized string similar to Specifies the parameter name for the &apos;{0}&apos; lambda expression..
/// </summary>
internal static string ChildContentParameterName_Documentation {
get {
return ResourceManager.GetString("ChildContentParameterName_Documentation", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Sets the &apos;{0}&apos; attribute to the provided string or delegate value. A delegate value should be of type &apos;{1}&apos;..
/// </summary>

View File

@ -132,6 +132,9 @@
<data name="BindTagHelper_Fallback_Format_Documentation" xml:space="preserve">
<value>Specifies a format to convert the value specified by the corresponding bind attribute. For example: &lt;code&gt;format-value="..."&lt;/code&gt; will apply a format string to the value specified in &lt;code&gt;bind-value-...&lt;/code&gt;. The format string can currently only be used with expressions of type &lt;code&gt;DateTime&lt;/code&gt;.</value>
</data>
<data name="ChildContentParameterName_Documentation" xml:space="preserve">
<value>Specifies the parameter name for the '{0}' lambda expression.</value>
</data>
<data name="EventHandlerTagHelper_Documentation" xml:space="preserve">
<value>Sets the '{0}' attribute to the provided string or delegate value. A delegate value should be of type '{1}'.</value>
</data>

View File

@ -26,19 +26,39 @@ namespace Microsoft.AspNetCore.Blazor.Razor
_stack.Push(new ScopeEntry(tagName, ScopeKind.Element));
}
public void OpenComponentScope(string tagName)
public void OpenComponentScope(CodeRenderingContext context, string name, string type, string parameterName)
{
_stack.Push(new ScopeEntry(tagName, ScopeKind.Component));
var scope = new ScopeEntry(name, ScopeKind.Component);
_stack.Push(scope);
var blazorNodeWriter = (BlazorNodeWriter)context.NodeWriter;
blazorNodeWriter.BeginWriteAttribute(context.CodeWriter, name);
OffsetBuilderVarNumber(1);
// Writes code that looks like:
//
// builder.AddAttribute(0, "{name}", ({type})((__builder) => { ... }));
// OR
// builder.AddAttribute(0, "{name}", ({type})((context) => (__builder) => { ... }));
context.CodeWriter.Write($"({type})(");
if (parameterName != null)
{
context.CodeWriter.Write($"({parameterName}) => ");
}
scope.LambdaScope = context.CodeWriter.BuildLambda(BuilderVarName);
}
public void OpenTemplateScope(CodeRenderingContext context, string variableName)
public void OpenTemplateScope(CodeRenderingContext context)
{
var currentScope = new ScopeEntry("__template", ScopeKind.Template);
_stack.Push(currentScope);
// Templates always get a lambda scope, because they are defined as a lambda.
OffsetBuilderVarNumber(1);
currentScope.LambdaScope = context.CodeWriter.BuildLambda(BuilderVarName, variableName);
currentScope.LambdaScope = context.CodeWriter.BuildLambda(BuilderVarName);
}
@ -61,27 +81,6 @@ namespace Microsoft.AspNetCore.Blazor.Razor
}
}
public void IncrementCurrentScopeChildCount(CodeRenderingContext context)
{
if (_stack.Count > 0)
{
var currentScope = _stack.Peek();
if (currentScope.Kind == ScopeKind.Component && currentScope.ChildCount == 0)
{
// When we're about to insert the first child into a component,
// it's time to open a new lambda
var blazorNodeWriter = (BlazorNodeWriter)context.NodeWriter;
blazorNodeWriter.BeginWriteAttribute(context.CodeWriter, BlazorApi.RenderTreeBuilder.ChildContent);
OffsetBuilderVarNumber(1);
context.CodeWriter.Write($"({BlazorApi.RenderFragment.FullTypeName})(");
currentScope.LambdaScope = context.CodeWriter.BuildLambda(BuilderVarName);
}
currentScope.ChildCount++;
}
}
private void OffsetBuilderVarNumber(int delta)
{
_builderVarNumber += delta;
@ -92,19 +91,19 @@ namespace Microsoft.AspNetCore.Blazor.Razor
private class ScopeEntry
{
public readonly string TagName;
public readonly string Name;
public ScopeKind Kind;
public int ChildCount;
public IDisposable LambdaScope;
public ScopeEntry(string tagName, ScopeKind kind)
public ScopeEntry(string name, ScopeKind kind)
{
TagName = tagName;
Name = name;
Kind = kind;
ChildCount = 0;
}
public override string ToString() => $"<{TagName}> ({Kind})";
public override string ToString() => $"<{Name}> ({Kind})";
}
private enum ScopeKind

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Blazor.Shared;
using Microsoft.AspNetCore.Razor.Language;
namespace Microsoft.AspNetCore.Blazor.Razor
@ -33,5 +34,41 @@ namespace Microsoft.AspNetCore.Blazor.Razor
attribute.Metadata.TryGetValue(key, out var value) &&
string.Equals(value, bool.TrueString);
}
/// <summary>
/// Gets a value that indicates whether the property is a child content property. Properties are
/// considered child content if they have the type <c>RenderFragment</c> or <c>RenderFragment{T}</c>.
/// </summary>
/// <param name="attribute">The <see cref="BoundAttributeDescriptor"/>.</param>
/// <returns>Returns <c>true</c> if the property is child content, otherwise <c>false</c>.</returns>
public static bool IsChildContentProperty(this BoundAttributeDescriptor attribute)
{
if (attribute == null)
{
throw new ArgumentNullException(nameof(attribute));
}
var key = BlazorMetadata.Component.ChildContentKey;
return
attribute.Metadata.TryGetValue(key, out var value) &&
string.Equals(value, bool.TrueString);
}
/// <summary>
/// Gets a value that indicates whether the property is a parameterized child content property. Properties are
/// considered parameterized child content if they have the type <c>RenderFragment{T}</c> (for some T).
/// </summary>
/// <param name="attribute">The <see cref="BoundAttributeDescriptor"/>.</param>
/// <returns>Returns <c>true</c> if the property is parameterized child content, otherwise <c>false</c>.</returns>
public static bool IsParameterizedChildContentProperty(this BoundAttributeDescriptor attribute)
{
if (attribute == null)
{
throw new ArgumentNullException(nameof(attribute));
}
return attribute.IsChildContentProperty() &&
!string.Equals(attribute.TypeName, BlazorApi.RenderFragment.FullTypeName, StringComparison.Ordinal);
}
}
}

View File

@ -1,8 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Razor.Language;
namespace Microsoft.AspNetCore.Blazor.Razor
@ -81,6 +82,18 @@ namespace Microsoft.AspNetCore.Blazor.Razor
return result;
}
public static bool IsChildContentTagHelper(this TagHelperDescriptor tagHelper)
{
if (tagHelper == null)
{
throw new ArgumentNullException(nameof(tagHelper));
}
return
tagHelper.Metadata.TryGetValue(BlazorMetadata.SpecialKindKey, out var value) &&
string.Equals(value, BlazorMetadata.ChildContent.TagHelperKind, StringComparison.Ordinal);
}
public static bool IsComponentTagHelper(this TagHelperDescriptor tagHelper)
{
if (tagHelper == null)
@ -125,5 +138,27 @@ namespace Microsoft.AspNetCore.Blazor.Razor
tagHelper.Metadata.TryGetValue(BlazorMetadata.EventHandler.EventArgsType, out var result);
return result;
}
/// <summary>
/// Gets the set of component attributes that can accept child content (<c>RenderFragment</c> or <c>RenderFragment{T}</c>).
/// </summary>
/// <param name="tagHelper">The <see cref="TagHelperDescriptor"/>.</param>
/// <returns>The child content attributes</returns>
public static IEnumerable<BoundAttributeDescriptor> GetChildContentProperties(this TagHelperDescriptor tagHelper)
{
if (tagHelper == null)
{
throw new ArgumentNullException(nameof(tagHelper));
}
for (var i = 0; i < tagHelper.BoundAttributes.Count; i++)
{
var attribute = tagHelper.BoundAttributes[i];
if (attribute.IsChildContentProperty())
{
yield return attribute;
}
}
}
}
}

View File

@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
for (var i = 0; i < visitor.Candidates.Count; i++)
{
var candidate = visitor.Candidates[i];
candidate.Parent.Diagnostics.Add(BlazorDiagnosticFactory.CreateTemplate_InvalidLocation(candidate.Node.Source));
candidate.Parent.Diagnostics.Add(BlazorDiagnosticFactory.Create_TemplateInvalidLocation(candidate.Node.Source));
// Remove the offending node since we don't know how to render it. This means that the user won't get C#
// completion at this location, which is fine because it's inside an HTML attribute.

View File

@ -13,11 +13,10 @@ namespace Microsoft.AspNetCore.Blazor
public delegate void RenderFragment(RenderTreeBuilder builder);
/// <summary>
/// Represents a segment of UI content for an object of type <typeparamref name="T"/>, implemented
/// as a delegate that writes the content to a <see cref="RenderTreeBuilder"/>.
/// Represents a segment of UI content for an object of type <typeparamref name="T"/>, implemented as
/// a function that returns a <see cref="RenderFragment"/>.
/// </summary>
/// <typeparam name="T">The type of object.</typeparam>
/// <param name="builder">The <see cref="RenderTreeBuilder"/> to which the content should be written.</param>
/// <param name="value">The value used to build the content.</param>
public delegate void RenderFragment<T>(RenderTreeBuilder builder, T value);
public delegate RenderFragment RenderFragment<T>(T value);
}

View File

@ -1,24 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Blazor
{
/// <summary>
/// Contains extension methods for <see cref="RenderFragment"/> and <see cref="RenderFragment{T}"/>.
/// </summary>
public static class RenderFragmentExtensions
{
/// <summary>
/// Binds a <see cref="RenderFragment{T}" /> and a value of type <typeparamref name="T"/> to a
/// <see cref="RenderFragment"/> so that it can be used by the rendering system from Razor code.
/// </summary>
/// <typeparam name="T">The type of the value used by the <paramref name="fragment"/>.</typeparam>
/// <param name="fragment">A <see cref="RenderFragment{T}"/>, usually produced by a Razor template.</param>
/// <param name="value">The value of type <typeparamref name="T"/>.</param>
/// <returns>A <see cref="RenderFragment"/>.</returns>
public static RenderFragment WithValue<T>(this RenderFragment<T> fragment, T value)
{
return (b) => fragment(b, value);
}
}
}

View File

@ -112,13 +112,7 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
{
if (fragment != null)
{
// We surround the fragment with a region delimiter to indicate that the
// sequence numbers inside the fragment are unrelated to the sequence numbers
// outside it. If we didn't do this, the diffing logic might produce inefficient
// diffs depending on how the sequence numbers compared.
OpenRegion(sequence);
fragment(this, value);
CloseRegion();
AddContent(sequence, fragment(value));
}
}

View File

@ -13,6 +13,7 @@ namespace Microsoft.AspNetCore.Blazor.Shared
{
public static readonly string Namespace = "Microsoft.AspNetCore.Blazor.Components";
public static readonly string FullTypeName = Namespace + ".BlazorComponent";
public static readonly string MetadataName = FullTypeName;
public static readonly string BuildRenderTree = nameof(BuildRenderTree);
}
@ -20,6 +21,7 @@ namespace Microsoft.AspNetCore.Blazor.Shared
public static class ParameterAttribute
{
public static readonly string FullTypeName = "Microsoft.AspNetCore.Blazor.Components.ParameterAttribute";
public static readonly string MetadataName = FullTypeName;
}
public static class LayoutAttribute
@ -43,8 +45,16 @@ namespace Microsoft.AspNetCore.Blazor.Shared
{
public static readonly string Namespace = "Microsoft.AspNetCore.Blazor";
public static readonly string FullTypeName = Namespace + ".RenderFragment";
public static readonly string MetadataName = FullTypeName;
}
public static class RenderFragmentOfT
{
public static readonly string Namespace = "Microsoft.AspNetCore.Blazor";
public static readonly string FullTypeName = Namespace + ".RenderFragment<>";
public static readonly string MetadataName = Namespace + ".RenderFragment`1";
}
public static class RenderTreeBuilder
{
public static readonly string FullTypeName = "Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder";

View File

@ -0,0 +1,496 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
using Microsoft.AspNetCore.Blazor.Razor;
using Microsoft.AspNetCore.Blazor.RenderTree;
using Microsoft.AspNetCore.Blazor.Test.Helpers;
using Microsoft.CodeAnalysis.CSharp;
using Xunit;
namespace Microsoft.AspNetCore.Blazor.Build.Test
{
public class ChildContentRazorIntegrationTest : RazorIntegrationTestBase
{
private readonly CSharpSyntaxTree RenderChildContentComponent = Parse(@"
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
using Microsoft.AspNetCore.Blazor.RenderTree;
namespace Test
{
public class RenderChildContent : BlazorComponent
{
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.AddContent(0, ChildContent);
}
[Parameter]
RenderFragment ChildContent { get; set; }
}
}
");
private readonly CSharpSyntaxTree RenderChildContentStringComponent = Parse(@"
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
using Microsoft.AspNetCore.Blazor.RenderTree;
namespace Test
{
public class RenderChildContentString : BlazorComponent
{
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.AddContent(0, ChildContent, Value);
}
[Parameter]
RenderFragment<string> ChildContent { get; set; }
[Parameter]
string Value { get; set; }
}
}
");
private readonly CSharpSyntaxTree RenderMultipleChildContent = Parse(@"
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
using Microsoft.AspNetCore.Blazor.RenderTree;
namespace Test
{
public class RenderMultipleChildContent : BlazorComponent
{
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.AddContent(0, Header, Name);
builder.AddContent(1, ChildContent, Value);
builder.AddContent(2, Footer);
}
[Parameter]
string Name { get; set; }
[Parameter]
RenderFragment<string> Header { get; set; }
[Parameter]
RenderFragment<string> ChildContent { get; set; }
[Parameter]
RenderFragment Footer { get; set; }
[Parameter]
string Value { get; set; }
}
}
");
internal override bool UseTwoPhaseCompilation => true;
[Fact]
public void Render_BodyChildContent()
{
// Arrange
AdditionalSyntaxTrees.Add(RenderChildContentComponent);
var component = CompileToComponent(@"
@addTagHelper *, TestAssembly
<RenderChildContent>
<div></div>
</RenderChildContent>");
// Act
var frames = GetRenderTree(component);
// Assert
Assert.Collection(
frames,
frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 0),
frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 1),
frame => AssertFrame.Markup(frame, "\n <div></div>\n", 2));
}
[Fact]
public void Render_BodyChildContent_Generic()
{
// Arrange
AdditionalSyntaxTrees.Add(RenderChildContentStringComponent);
var component = CompileToComponent(@"
@addTagHelper *, TestAssembly
<RenderChildContentString Value=""HI"">
<div>@context.ToLowerInvariant()</div>
</RenderChildContentString>");
// Act
var frames = GetRenderTree(component);
// Assert
Assert.Collection(
frames,
frame => AssertFrame.Component(frame, "Test.RenderChildContentString", 3, 0),
frame => AssertFrame.Attribute(frame, "Value", "HI", 1),
frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 2),
frame => AssertFrame.Whitespace(frame, 3),
frame => AssertFrame.Element(frame, "div", 2, 4),
frame => AssertFrame.Text(frame, "hi", 5),
frame => AssertFrame.Whitespace(frame, 6));
}
[Fact]
public void Render_ExplicitChildContent()
{
// Arrange
AdditionalSyntaxTrees.Add(RenderChildContentComponent);
var component = CompileToComponent(@"
@addTagHelper *, TestAssembly
<RenderChildContent>
<ChildContent>
<div></div>
</ChildContent>
</RenderChildContent>");
// Act
var frames = GetRenderTree(component);
// Assert
Assert.Collection(
frames,
frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 0),
frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 1),
frame => AssertFrame.Markup(frame, "\n <div></div>\n ", 2));
}
[Fact]
public void Render_BodyChildContent_Recursive()
{
// Arrange
AdditionalSyntaxTrees.Add(RenderChildContentComponent);
var component = CompileToComponent(@"
@addTagHelper *, TestAssembly
<RenderChildContent>
<RenderChildContent>
<div></div>
</RenderChildContent>
</RenderChildContent>");
// Act
var frames = GetRenderTree(component);
// Assert
Assert.Collection(
frames,
frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 0),
frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 1),
frame => AssertFrame.Whitespace(frame, 2),
frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 3),
frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 4),
frame => AssertFrame.Whitespace(frame, 6),
frame => AssertFrame.Markup(frame, "\n <div></div>\n ", 5));
}
[Fact]
public void Render_AttributeChildContent()
{
// Arrange
AdditionalSyntaxTrees.Add(RenderChildContentComponent);
var component = CompileToComponent(@"
@addTagHelper *, TestAssembly
@{ RenderFragment<string> template = (context) => @<div>@context.ToLowerInvariant()</div>; }
<RenderChildContent ChildContent=""@template(""HI"")"" />");
// Act
var frames = GetRenderTree(component);
// Assert
Assert.Collection(
frames,
frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 2),
frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 3),
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Text(frame, "hi", 1));
}
[Fact]
public void Render_AttributeChildContent_RenderFragmentOfString()
{
// Arrange
AdditionalSyntaxTrees.Add(RenderChildContentStringComponent);
var component = CompileToComponent(@"
@addTagHelper *, TestAssembly
@{ RenderFragment<string> template = (context) => @<div>@context.ToLowerInvariant()</div>; }
<RenderChildContentString ChildContent=""@template"" Value=""HI"" />");
// Act
var frames = GetRenderTree(component);
// Assert
Assert.Collection(
frames,
frame => AssertFrame.Component(frame, "Test.RenderChildContentString", 3, 2),
frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 3),
frame => AssertFrame.Attribute(frame, "Value", "HI", 4),
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Text(frame, "hi", 1));
}
[Fact]
public void Render_AttributeChildContent_NoArgTemplate()
{
// Arrange
AdditionalSyntaxTrees.Add(RenderChildContentComponent);
var component = CompileToComponent(@"
@addTagHelper *, TestAssembly
@{ RenderFragment template = @<div>@(""HI"".ToLowerInvariant())</div>; }
<RenderChildContent ChildContent=""@template"" />");
// Act
var frames = GetRenderTree(component);
// Assert
Assert.Collection(
frames,
frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 2),
frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 3),
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Text(frame, "hi", 1));
}
[Fact]
public void Render_AttributeChildContent_IgnoresEmptyBody()
{
// Arrange
AdditionalSyntaxTrees.Add(RenderChildContentComponent);
var component = CompileToComponent(@"
@addTagHelper *, TestAssembly
@{ RenderFragment<string> template = (context) => @<div>@context.ToLowerInvariant()</div>; }
<RenderChildContent ChildContent=""@template(""HI"")""></RenderChildContent>");
// Act
var frames = GetRenderTree(component);
// Assert
Assert.Collection(
frames,
frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 2),
frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 3),
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Text(frame, "hi", 1));
}
[Fact]
public void Render_AttributeChildContent_IgnoresWhitespaceBody()
{
// Arrange
AdditionalSyntaxTrees.Add(RenderChildContentComponent);
var component = CompileToComponent(@"
@addTagHelper *, TestAssembly
@{ RenderFragment<string> template = (context) => @<div>@context.ToLowerInvariant()</div>; }
<RenderChildContent ChildContent=""@template(""HI"")"">
</RenderChildContent>");
// Act
var frames = GetRenderTree(component);
// Assert
Assert.Collection(
frames,
frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 2),
frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 3),
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Text(frame, "hi", 1));
}
[Fact]
public void Render_MultipleChildContent()
{
// Arrange
AdditionalSyntaxTrees.Add(RenderMultipleChildContent);
var component = CompileToComponent(@"
@addTagHelper *, TestAssembly
@{ RenderFragment<string> header = context => @<div>@context.ToLowerInvariant()</div>; }
<RenderMultipleChildContent Name=""billg"" Header=@header Value=""HI"">
<ChildContent>Some @context.ToLowerInvariant() Content</ChildContent>
<Footer>Bye!</Footer>
</RenderMultipleChildContent>");
// Act
var frames = GetRenderTree(component);
// Assert
Assert.Collection(
frames,
frame => AssertFrame.Component(frame, "Test.RenderMultipleChildContent", 6, 2),
frame => AssertFrame.Attribute(frame, "Name", "billg", 3),
frame => AssertFrame.Attribute(frame, "Header", typeof(RenderFragment<string>), 4),
frame => AssertFrame.Attribute(frame, "Value", "HI", 5),
frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, typeof(RenderFragment<string>), 6),
frame => AssertFrame.Attribute(frame, "Footer", typeof(RenderFragment), 10),
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Text(frame, "billg", 1),
frame => AssertFrame.Text(frame, "Some ", 7),
frame => AssertFrame.Text(frame, "hi", 8),
frame => AssertFrame.Text(frame, " Content", 9),
frame => AssertFrame.Text(frame, "Bye!", 11));
}
[Fact]
public void Render_ChildContent_AttributeAndBody_ProducesDiagnostic()
{
// Arrange
AdditionalSyntaxTrees.Add(RenderChildContentComponent);
// Act
var generated = CompileToCSharp(@"
@addTagHelper *, TestAssembly
@{ RenderFragment<string> template = @<div>@context.ToLowerInvariant()</div>; }
<RenderChildContent ChildContent=""@template.WithValue(""HI"")"">
Some Content
</RenderChildContent>");
// Assert
var diagnostic = Assert.Single(generated.Diagnostics);
Assert.Same(BlazorDiagnosticFactory.ChildContentSetByAttributeAndBody.Id, diagnostic.Id);
}
[Fact]
public void Render_ChildContent_AttributeAndExplicitChildContent_ProducesDiagnostic()
{
// Arrange
AdditionalSyntaxTrees.Add(RenderChildContentComponent);
// Act
var generated = CompileToCSharp(@"
@addTagHelper *, TestAssembly
@{ RenderFragment<string> template = @<div>@context.ToLowerInvariant()</div>; }
<RenderChildContent ChildContent=""@template.WithValue(""HI"")"">
<ChildContent>
Some Content
</ChildContent>
</RenderChildContent>");
// Assert
var diagnostic = Assert.Single(generated.Diagnostics);
Assert.Same(BlazorDiagnosticFactory.ChildContentSetByAttributeAndBody.Id, diagnostic.Id);
}
[Fact]
public void Render_ChildContent_ExplicitChildContent_UnrecogizedContent_ProducesDiagnostic()
{
// Arrange
AdditionalSyntaxTrees.Add(RenderChildContentComponent);
// Act
var generated = CompileToCSharp(@"
@addTagHelper *, TestAssembly
<RenderChildContent>
<ChildContent>
</ChildContent>
@somethingElse
</RenderChildContent>");
// Assert
var diagnostic = Assert.Single(generated.Diagnostics);
Assert.Same(BlazorDiagnosticFactory.ChildContentMixedWithExplicitChildContent.Id, diagnostic.Id);
Assert.Equal(
"Unrecognized child content inside component 'RenderChildContent'. The component 'RenderChildContent' accepts " +
"child content through the following top-level items: 'ChildContent'.",
diagnostic.GetMessage());
}
[Fact]
public void Render_ChildContent_ExplicitChildContent_UnrecogizedElement_ProducesDiagnostic()
{
// Arrange
AdditionalSyntaxTrees.Add(RenderChildContentComponent);
// Act
var generated = CompileToCSharp(@"
@addTagHelper *, TestAssembly
<RenderChildContent>
<ChildContent>
</ChildContent>
<UnrecognizedChildContent></UnrecognizedChildContent>
</RenderChildContent>");
// Assert
var diagnostic = Assert.Single(generated.Diagnostics);
Assert.Same(BlazorDiagnosticFactory.ChildContentMixedWithExplicitChildContent.Id, diagnostic.Id);
}
[Fact]
public void Render_ChildContent_ExplicitChildContent_UnrecogizedAttribute_ProducesDiagnostic()
{
// Arrange
AdditionalSyntaxTrees.Add(RenderChildContentComponent);
// Act
var generated = CompileToCSharp(@"
@addTagHelper *, TestAssembly
<RenderChildContent>
<ChildContent attr>
</ChildContent>
</RenderChildContent>");
// Assert
var diagnostic = Assert.Single(generated.Diagnostics);
Assert.Same(BlazorDiagnosticFactory.ChildContentHasInvalidAttribute.Id, diagnostic.Id);
}
[Fact]
public void Render_ChildContent_ExplicitChildContent_InvalidParameterName_ProducesDiagnostic()
{
// Arrange
AdditionalSyntaxTrees.Add(RenderChildContentStringComponent);
// Act
var generated = CompileToCSharp(@"
@addTagHelper *, TestAssembly
<RenderChildContentString>
<ChildContent Context=""@(""HI"")"">
</ChildContent>
</RenderChildContentString>");
// Assert
var diagnostic = Assert.Single(generated.Diagnostics);
Assert.Same(BlazorDiagnosticFactory.ChildContentHasInvalidParameter.Id, diagnostic.Id);
}
[Fact]
public void Render_ChildContent_ExplicitChildContent_RepeatedParameterName_GeneratesDiagnostic()
{
// Arrange
AdditionalSyntaxTrees.Add(RenderChildContentStringComponent);
// Act
var generated = CompileToCSharp(@"
@addTagHelper *, TestAssembly
<RenderChildContentString>
<ChildContent>
<RenderChildContentString>
<ChildContent Context=""context"">
</ChildContent>
</RenderChildContentString>
</ChildContent>
</RenderChildContentString>");
// Assert
var diagnostic = Assert.Single(generated.Diagnostics);
Assert.Same(BlazorDiagnosticFactory.ChildContentRepeatedParameterName.Id, diagnostic.Id);
Assert.Equal(
"The child content element 'ChildContent' of component 'RenderChildContentString' uses the same parameter name ('context') as enclosing child content " +
"element 'ChildContent' of component 'RenderChildContentString'. Specify the parameter name like: '<ChildContent Context=\"another_name\"> to resolve the ambiguity",
diagnostic.GetMessage());
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -586,7 +586,7 @@ namespace Test
var component = CompileToComponent(@"
@addTagHelper ""*, TestAssembly""
@{ RenderFragment<string> template = @<div>@context.ToLower()</div>; }
@{ RenderFragment<string> template = (context) => @<div>@context.ToLower()</div>; }
<Repeater Count=3 Value=""Hello, World!"" Template=""template"" />
");

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Reflection;
@ -11,16 +11,16 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
{
public override void Before(MethodInfo methodUnderTest)
{
if (typeof(RazorBaselineIntegrationTestBase).GetTypeInfo().IsAssignableFrom(methodUnderTest.DeclaringType.GetTypeInfo()))
if (typeof(RazorBaselineIntegrationTestBase).GetTypeInfo().IsAssignableFrom(methodUnderTest.ReflectedType.GetTypeInfo()))
{
var typeName = methodUnderTest.DeclaringType.Name;
var typeName = methodUnderTest.ReflectedType.Name;
RazorBaselineIntegrationTestBase.DirectoryPath = $"TestFiles/{typeName}/{methodUnderTest.Name}";
}
}
public override void After(MethodInfo methodUnderTest)
{
if (typeof(RazorBaselineIntegrationTestBase).GetTypeInfo().IsAssignableFrom(methodUnderTest.DeclaringType.GetTypeInfo()))
if (typeof(RazorBaselineIntegrationTestBase).GetTypeInfo().IsAssignableFrom(methodUnderTest.ReflectedType.GetTypeInfo()))
{
RazorBaselineIntegrationTestBase.DirectoryPath = null;
}

View File

@ -18,6 +18,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
IExtensionIntermediateNodeVisitor<HtmlBlockIntermediateNode>,
IExtensionIntermediateNodeVisitor<ComponentExtensionNode>,
IExtensionIntermediateNodeVisitor<ComponentAttributeExtensionNode>,
IExtensionIntermediateNodeVisitor<ComponentChildContentIntermediateNode>,
IExtensionIntermediateNodeVisitor<RouteAttributeExtensionNode>,
IExtensionIntermediateNodeVisitor<RefExtensionNode>
{
@ -285,6 +286,11 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
WriteContentNode(node, node.AttributeName, node.PropertyName);
}
void IExtensionIntermediateNodeVisitor<ComponentChildContentIntermediateNode>.VisitExtension(ComponentChildContentIntermediateNode node)
{
WriteContentNode(node, node.AttributeName);
}
void IExtensionIntermediateNodeVisitor<RouteAttributeExtensionNode>.VisitExtension(RouteAttributeExtensionNode node)
{
WriteContentNode(node, node.Template);

View File

@ -600,14 +600,14 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
public enum MyEnum { FirstValue, SecondValue }
[Fact]
public void RazorTemplate_CanBeUsedFromRazorCode()
public void RazorTemplate_NonGeneric_CanBeUsedFromRazorCode()
{
// Arrange
var component = CompileToComponent(@"
@{ RenderFragment<string> template = @<div>@context.ToLower()</div>; }
@{ RenderFragment template = @<div>@(""Hello, World!"".ToLower())</div>; }
@for (var i = 0; i < 3; i++)
{
@template.WithValue(""Hello, World!"");
@template;
}
");
@ -626,11 +626,75 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
}
[Fact]
public void RazorTemplate_CanBeUsedFromMethod()
public void RazorTemplate_Generic_CanBeUsedFromRazorCode()
{
// Arrange
var component = CompileToComponent(@"
@(Repeat(@<div>@context.ToLower()</div>, ""Hello, World!"", 3))
@{ RenderFragment<string> template = (context) => @<div>@context.ToLower()</div>; }
@for (var i = 0; i < 3; i++)
{
@template(""Hello, World!"");
}
");
// Act
var frames = GetRenderTree(component);
// Assert
Assert.Collection(
frames,
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Text(frame, "hello, world!", 1),
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Text(frame, "hello, world!", 1),
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Text(frame, "hello, world!", 1));
}
[Fact]
public void RazorTemplate_NonGeneric_CanBeUsedFromMethod()
{
// Arrange
var component = CompileToComponent(@"
@(Repeat(@<div>@(""Hello, World!"".ToLower())</div>, 3))
@functions {
RenderFragment Repeat(RenderFragment template, int count)
{
return (b) =>
{
for (var i = 0; i < count; i++)
{
b.AddContent(i, template);
}
};
}
}");
// Act
var frames = GetRenderTree(component);
// Assert
//
// The sequence numbers start at 1 here because there is an AddContent(0, Repeat(....) call
// that precedes the definition of the lambda. Sequence numbers for the lambda are allocated
// from the same logical sequence as the surrounding code.
Assert.Collection(
frames,
frame => AssertFrame.Element(frame, "div", 2, 1),
frame => AssertFrame.Text(frame, "hello, world!", 2),
frame => AssertFrame.Element(frame, "div", 2, 1),
frame => AssertFrame.Text(frame, "hello, world!", 2),
frame => AssertFrame.Element(frame, "div", 2, 1),
frame => AssertFrame.Text(frame, "hello, world!", 2));
}
[Fact]
public void RazorTemplate_Generic_CanBeUsedFromMethod()
{
// Arrange
var component = CompileToComponent(@"
@(Repeat((context) => @<div>@context.ToLower()</div>, ""Hello, World!"", 3))
@functions {
RenderFragment Repeat<T>(RenderFragment<T> template, T value, int count)
@ -639,7 +703,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
{
for (var i = 0; i < count; i++)
{
template(b, value);
b.AddContent(i, template, value);
}
};
}

View File

@ -5,7 +5,7 @@ using Xunit;
namespace Microsoft.AspNetCore.Blazor.Build.Test
{
public class TemplateRazorIntegrationTest : RazorBaselineIntegrationTestBase
public class TemplateRazorIntegrationTest : RazorIntegrationTestBase
{
// Razor doesn't parse this as a template, we don't need much special handling for
// it because it will just be invalid in general.

View File

@ -0,0 +1,60 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
((System.Action)(() => {
global::System.Object __typeHelper = "*, TestAssembly";
}
))();
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
RenderFragment<string> header = (context) =>
#line default
#line hidden
(builder2) => {
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = context.ToLowerInvariant();
#line default
#line hidden
}
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
;
#line default
#line hidden
__o = new Microsoft.AspNetCore.Blazor.RenderFragment<System.String>(
#line 3 "x:\dir\subdir\Test\TestComponent.cshtml"
header
#line default
#line hidden
);
builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => {
}
));
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,39 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [12] ) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
DesignTimeDirective -
DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor"
DirectiveToken - (14:0,14 [9] ) - "*, Test"
DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
CSharpCode - (33:1,2 [46] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (33:1,2 [46] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderFragment<string> header = (context) =>
Template - (80:1,49 [37] x:\dir\subdir\Test\TestComponent.cshtml)
HtmlElement - (80:1,49 [38] x:\dir\subdir\Test\TestComponent.cshtml) - div
CSharpExpression - (86:1,55 [26] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (86:1,55 [26] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.ToLowerInvariant()
CSharpCode - (118:1,87 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (118:1,87 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;
ComponentExtensionNode - (123:2,0 [62] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent
ComponentChildContent - - ChildContent
HtmlContent - (151:2,28 [20] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (151:2,28 [20] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n Some Content\n
ComponentAttributeExtensionNode - (143:2,20 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Header - Header
CSharpExpression - (144:2,21 [6] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (144:2,21 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - header

View File

@ -0,0 +1,25 @@
Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml)
|*, TestAssembly|
Generated Location: (559:16,38 [15] )
|*, TestAssembly|
Source Location: (33:1,2 [46] x:\dir\subdir\Test\TestComponent.cshtml)
| RenderFragment<string> header = (context) => |
Generated Location: (1039:29,2 [46] )
| RenderFragment<string> header = (context) => |
Source Location: (86:1,55 [26] x:\dir\subdir\Test\TestComponent.cshtml)
|context.ToLowerInvariant()|
Generated Location: (1253:35,55 [26] )
|context.ToLowerInvariant()|
Source Location: (118:1,87 [2] x:\dir\subdir\Test\TestComponent.cshtml)
|; |
Generated Location: (1466:41,87 [2] )
|; |
Source Location: (144:2,21 [6] x:\dir\subdir\Test\TestComponent.cshtml)
|header|
Generated Location: (1655:47,21 [6] )
|header|

View File

@ -0,0 +1,63 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
((System.Action)(() => {
global::System.Object __typeHelper = "*, TestAssembly";
}
))();
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
RenderFragment<string> header = (context) =>
#line default
#line hidden
(builder2) => {
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = context.ToLowerInvariant();
#line default
#line hidden
}
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
;
#line default
#line hidden
__o = new Microsoft.AspNetCore.Blazor.RenderFragment<System.String>(
#line 3 "x:\dir\subdir\Test\TestComponent.cshtml"
header
#line default
#line hidden
);
builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => {
}
));
builder.AddAttribute(-1, "Footer", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => {
}
));
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,42 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [12] ) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
DesignTimeDirective -
DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor"
DirectiveToken - (14:0,14 [9] ) - "*, Test"
DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
CSharpCode - (33:1,2 [46] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (33:1,2 [46] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderFragment<string> header = (context) =>
Template - (80:1,49 [37] x:\dir\subdir\Test\TestComponent.cshtml)
HtmlElement - (80:1,49 [38] x:\dir\subdir\Test\TestComponent.cshtml) - div
CSharpExpression - (86:1,55 [26] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (86:1,55 [26] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.ToLowerInvariant()
CSharpCode - (118:1,87 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (118:1,87 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;
ComponentExtensionNode - (123:2,0 [114] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent
ComponentChildContent - (155:3,2 [41] x:\dir\subdir\Test\TestComponent.cshtml) - ChildContent
HtmlContent - (169:3,16 [12] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (169:3,16 [12] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Some Content
ComponentChildContent - (200:4,2 [21] x:\dir\subdir\Test\TestComponent.cshtml) - Footer
HtmlContent - (208:4,10 [4] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (208:4,10 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Bye!
ComponentAttributeExtensionNode - (143:2,20 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Header - Header
CSharpExpression - (144:2,21 [6] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (144:2,21 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - header

View File

@ -0,0 +1,25 @@
Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml)
|*, TestAssembly|
Generated Location: (559:16,38 [15] )
|*, TestAssembly|
Source Location: (33:1,2 [46] x:\dir\subdir\Test\TestComponent.cshtml)
| RenderFragment<string> header = (context) => |
Generated Location: (1039:29,2 [46] )
| RenderFragment<string> header = (context) => |
Source Location: (86:1,55 [26] x:\dir\subdir\Test\TestComponent.cshtml)
|context.ToLowerInvariant()|
Generated Location: (1253:35,55 [26] )
|context.ToLowerInvariant()|
Source Location: (118:1,87 [2] x:\dir\subdir\Test\TestComponent.cshtml)
|; |
Generated Location: (1466:41,87 [2] )
|; |
Source Location: (144:2,21 [6] x:\dir\subdir\Test\TestComponent.cshtml)
|header|
Generated Location: (1655:47,21 [6] )
|header|

View File

@ -0,0 +1,36 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
((System.Action)(() => {
global::System.Object __typeHelper = "*, TestAssembly";
}
))();
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => {
}
));
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,25 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [12] ) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
DesignTimeDirective -
DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor"
DirectiveToken - (14:0,14 [9] ) - "*, Test"
DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
ComponentExtensionNode - (31:1,0 [15] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent

View File

@ -0,0 +1,5 @@
Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml)
|*, TestAssembly|
Generated Location: (559:16,38 [15] )
|*, TestAssembly|

View File

@ -23,14 +23,15 @@ Document -
HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
ComponentExtensionNode - (31:1,0 [91] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent
HtmlContent - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Some text
HtmlElement - (66:1,35 [42] x:\dir\subdir\Test\TestComponent.cshtml) - some-child
HtmlAttribute - - -
HtmlAttributeValue - -
IntermediateToken - - Html - 1
HtmlContent - (84:1,53 [11] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (84:1,53 [11] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Nested text
ComponentChildContent - - ChildContent
HtmlContent - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Some text
HtmlElement - (66:1,35 [42] x:\dir\subdir\Test\TestComponent.cshtml) - some-child
HtmlAttribute - - -
HtmlAttributeValue - -
IntermediateToken - - Html - 1
HtmlContent - (84:1,53 [11] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (84:1,53 [11] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Nested text
ComponentAttributeExtensionNode - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - MyAttr - MyAttr
HtmlContent - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - abc

View File

@ -23,6 +23,7 @@ Document -
HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
ComponentExtensionNode - (31:1,0 [47] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent
HtmlElement - (44:1,13 [20] x:\dir\subdir\Test\TestComponent.cshtml) - child
HtmlContent - (51:1,20 [5] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (51:1,20 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - hello
ComponentChildContent - - ChildContent
HtmlElement - (44:1,13 [20] x:\dir\subdir\Test\TestComponent.cshtml) - child
HtmlContent - (51:1,20 [5] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (51:1,20 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - hello

View File

@ -0,0 +1,36 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
((System.Action)(() => {
global::System.Object __typeHelper = "*, TestAssembly";
}
))();
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => {
}
));
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,28 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [12] ) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
DesignTimeDirective -
DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor"
DirectiveToken - (14:0,14 [9] ) - "*, Test"
DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
ComponentExtensionNode - (31:1,0 [61] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent
ComponentChildContent - (44:1,13 [34] x:\dir\subdir\Test\TestComponent.cshtml) - ChildContent
HtmlContent - (58:1,27 [5] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (58:1,27 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - hello

View File

@ -0,0 +1,5 @@
Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml)
|*, TestAssembly|
Generated Location: (559:16,38 [15] )
|*, TestAssembly|

View File

@ -0,0 +1,41 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
((System.Action)(() => {
global::System.Object __typeHelper = "*, TestAssembly";
}
))();
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment<System.String>)((context) => (builder2) => {
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = context;
#line default
#line hidden
}
));
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,28 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [12] ) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
DesignTimeDirective -
DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor"
DirectiveToken - (14:0,14 [9] ) - "*, Test"
DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
ComponentExtensionNode - (31:1,0 [64] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent
ComponentChildContent - (44:1,13 [37] x:\dir\subdir\Test\TestComponent.cshtml) - ChildContent
CSharpExpression - (59:1,28 [7] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (59:1,28 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context

View File

@ -0,0 +1,10 @@
Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml)
|*, TestAssembly|
Generated Location: (559:16,38 [15] )
|*, TestAssembly|
Source Location: (59:1,28 [7] x:\dir\subdir\Test\TestComponent.cshtml)
|context|
Generated Location: (1208:30,28 [7] )
|context|

View File

@ -0,0 +1,41 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
((System.Action)(() => {
global::System.Object __typeHelper = "*, TestAssembly";
}
))();
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment<System.String>)((context) => (builder2) => {
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = context.ToLowerInvariant();
#line default
#line hidden
}
));
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,37 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [12] ) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
DesignTimeDirective -
DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor"
DirectiveToken - (14:0,14 [9] ) - "*, Test"
DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
ComponentExtensionNode - (31:1,0 [107] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent
ComponentChildContent - - ChildContent
HtmlContent - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Some text
HtmlElement - (66:1,35 [58] x:\dir\subdir\Test\TestComponent.cshtml) - some-child
HtmlAttribute - - -
HtmlAttributeValue - -
IntermediateToken - - Html - 1
CSharpExpression - (85:1,54 [26] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (85:1,54 [26] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.ToLowerInvariant()
ComponentAttributeExtensionNode - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - MyAttr - MyAttr
HtmlContent - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - abc

View File

@ -0,0 +1,10 @@
Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml)
|*, TestAssembly|
Generated Location: (559:16,38 [15] )
|*, TestAssembly|
Source Location: (85:1,54 [26] x:\dir\subdir\Test\TestComponent.cshtml)
|context.ToLowerInvariant()|
Generated Location: (1234:30,54 [26] )
|context.ToLowerInvariant()|

View File

@ -0,0 +1,41 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
((System.Action)(() => {
global::System.Object __typeHelper = "*, TestAssembly";
}
))();
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment<System.String>)((item) => (builder2) => {
#line 4 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = item.ToLowerInvariant();
#line default
#line hidden
}
));
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,39 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [12] ) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
DesignTimeDirective -
DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor"
DirectiveToken - (14:0,14 [9] ) - "*, Test"
DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
ComponentExtensionNode - (31:1,0 [164] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent
ComponentChildContent - (61:2,2 [118] x:\dir\subdir\Test\TestComponent.cshtml) - ChildContent
HtmlContent - (90:2,31 [15] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (90:2,31 [15] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n Some text
HtmlElement - (105:3,13 [55] x:\dir\subdir\Test\TestComponent.cshtml) - some-child
HtmlAttribute - - -
HtmlAttributeValue - -
IntermediateToken - - Html - 1
CSharpExpression - (124:3,32 [23] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (124:3,32 [23] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - item.ToLowerInvariant()
HtmlContent - (160:3,68 [4] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (160:3,68 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
ComponentAttributeExtensionNode - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - MyAttr - MyAttr
HtmlContent - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - abc

View File

@ -0,0 +1,10 @@
Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml)
|*, TestAssembly|
Generated Location: (559:16,38 [15] )
|*, TestAssembly|
Source Location: (124:3,32 [23] x:\dir\subdir\Test\TestComponent.cshtml)
|item.ToLowerInvariant()|
Generated Location: (1209:30,32 [23] )
|item.ToLowerInvariant()|

View File

@ -28,7 +28,7 @@ global::System.Object __typeHelper = "*, TestAssembly";
base.BuildRenderTree(builder);
__o = new System.Action<Microsoft.AspNetCore.Blazor.UIEventArgs>(
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
(e) => { Increment(); }
e => { Increment(); }
#line default
#line hidden

View File

@ -22,11 +22,11 @@ Document -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
ComponentExtensionNode - (31:1,0 [51] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent
ComponentAttributeExtensionNode - (53:1,22 [26] x:\dir\subdir\Test\TestComponent.cshtml) - OnClick - OnClick
CSharpExpression - (54:1,23 [25] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (55:1,24 [23] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - (e) => { Increment(); }
HtmlContent - (82:1,51 [4] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (82:1,51 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n
CSharpCode - (98:3,12 [87] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (98:3,12 [87] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private int counter;\n private void Increment() {\n counter++;\n }\n
ComponentExtensionNode - (31:1,0 [49] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent
ComponentAttributeExtensionNode - (53:1,22 [24] x:\dir\subdir\Test\TestComponent.cshtml) - OnClick - OnClick
CSharpExpression - (54:1,23 [23] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (55:1,24 [21] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - e => { Increment(); }
HtmlContent - (80:1,49 [4] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (80:1,49 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n
CSharpCode - (96:3,12 [87] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (96:3,12 [87] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private int counter;\n private void Increment() {\n counter++;\n }\n

View File

@ -3,19 +3,19 @@ Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml)
Generated Location: (559:16,38 [15] )
|*, TestAssembly|
Source Location: (55:1,24 [23] x:\dir\subdir\Test\TestComponent.cshtml)
|(e) => { Increment(); }|
Generated Location: (1140:30,24 [23] )
|(e) => { Increment(); }|
Source Location: (55:1,24 [21] x:\dir\subdir\Test\TestComponent.cshtml)
|e => { Increment(); }|
Generated Location: (1140:30,24 [21] )
|e => { Increment(); }|
Source Location: (98:3,12 [87] x:\dir\subdir\Test\TestComponent.cshtml)
Source Location: (96:3,12 [87] x:\dir\subdir\Test\TestComponent.cshtml)
|
private int counter;
private void Increment() {
counter++;
}
|
Generated Location: (1471:41,12 [87] )
Generated Location: (1469:41,12 [87] )
|
private int counter;
private void Increment() {

View File

@ -0,0 +1,46 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
[Microsoft.AspNetCore.Blazor.Components.RouteAttribute("/MyPage")]
[Microsoft.AspNetCore.Blazor.Components.RouteAttribute("/AnotherRoute/{id}")]
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
((System.Action)(() => {
global::System.Object __typeHelper = "*, TestAssembly";
}
))();
((System.Action)(() => {
global::System.Object __typeHelper = "/MyPage";
}
))();
((System.Action)(() => {
global::System.Object __typeHelper = "/AnotherRoute/{id}";
}
))();
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => {
}
));
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,29 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [12] ) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components
RouteAttributeExtensionNode - - /MyPage
RouteAttributeExtensionNode - - /AnotherRoute/{id}
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
DesignTimeDirective -
DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor"
DirectiveToken - (14:0,14 [9] ) - "*, Test"
DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly
DirectiveToken - (37:1,6 [9] x:\dir\subdir\Test\TestComponent.cshtml) - "/MyPage"
DirectiveToken - (54:2,6 [20] x:\dir\subdir\Test\TestComponent.cshtml) - "/AnotherRoute/{id}"
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
ComponentExtensionNode - (76:3,0 [15] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent

View File

@ -0,0 +1,15 @@
Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml)
|*, TestAssembly|
Generated Location: (714:18,38 [15] )
|*, TestAssembly|
Source Location: (37:1,6 [9] x:\dir\subdir\Test\TestComponent.cshtml)
|"/MyPage"|
Generated Location: (830:22,37 [9] )
|"/MyPage"|
Source Location: (54:2,6 [20] x:\dir\subdir\Test\TestComponent.cshtml)
|"/AnotherRoute/{id}"|
Generated Location: (939:26,37 [20] )
|"/AnotherRoute/{id}"|

View File

@ -38,9 +38,8 @@ global::System.Object __typeHelper = "*, TestAssembly";
#pragma warning restore 1998
#line 4 "x:\dir\subdir\Test\TestComponent.cshtml"
Test.MyComponent myInstance;
void DoSomething() { myInstance.GetHashCode(); } // Avoid 'assigned but not used' warning
private Test.MyComponent myInstance;
public void Foo() { System.GC.KeepAlive(myInstance); }
#line default
#line hidden

View File

@ -32,7 +32,7 @@ Document -
IntermediateToken - (94:1,63 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - after
HtmlContent - (103:1,72 [4] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (103:1,72 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n
HtmlContent - (253:7,1 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (253:7,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
CSharpCode - (119:3,12 [133] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (119:3,12 [133] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n Test.MyComponent myInstance;\n\n void DoSomething() { myInstance.GetHashCode(); } // Avoid 'assigned but not used' warning\n
HtmlContent - (224:6,1 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (224:6,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
CSharpCode - (119:3,12 [104] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (119:3,12 [104] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private Test.MyComponent myInstance;\n public void Foo() { System.GC.KeepAlive(myInstance); }\n

View File

@ -8,16 +8,14 @@ Source Location: (70:1,39 [10] x:\dir\subdir\Test\TestComponent.cshtml)
Generated Location: (1223:32,39 [10] )
|myInstance|
Source Location: (119:3,12 [133] x:\dir\subdir\Test\TestComponent.cshtml)
Source Location: (119:3,12 [104] x:\dir\subdir\Test\TestComponent.cshtml)
|
Test.MyComponent myInstance;
void DoSomething() { myInstance.GetHashCode(); } // Avoid 'assigned but not used' warning
private Test.MyComponent myInstance;
public void Foo() { System.GC.KeepAlive(myInstance); }
|
Generated Location: (1407:39,12 [133] )
Generated Location: (1407:39,12 [104] )
|
Test.MyComponent myInstance;
void DoSomething() { myInstance.GetHashCode(); } // Avoid 'assigned but not used' warning
private Test.MyComponent myInstance;
public void Foo() { System.GC.KeepAlive(myInstance); }
|

View File

@ -0,0 +1,48 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
((System.Action)(() => {
global::System.Object __typeHelper = "*, TestAssembly";
}
))();
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => {
}
));
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
myInstance = default(Test.MyComponent);
#line default
#line hidden
}
#pragma warning restore 1998
#line 6 "x:\dir\subdir\Test\TestComponent.cshtml"
private Test.MyComponent myInstance;
public void Foo() { System.GC.KeepAlive(myInstance); }
#line default
#line hidden
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,43 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [12] ) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
DesignTimeDirective -
DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor"
DirectiveToken - (14:0,14 [9] ) - "*, Test"
DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
ComponentExtensionNode - (31:1,0 [96] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent
ComponentChildContent - - ChildContent
HtmlContent - (76:1,45 [11] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (76:1,45 [11] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n Some
HtmlElement - (87:2,9 [16] x:\dir\subdir\Test\TestComponent.cshtml) - el
HtmlContent - (91:2,13 [7] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (91:2,13 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Html - further
HtmlContent - (103:2,25 [10] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (103:2,25 [10] x:\dir\subdir\Test\TestComponent.cshtml) - Html - content\n
RefExtensionNode - (49:1,18 [10] x:\dir\subdir\Test\TestComponent.cshtml) - myInstance - Test.MyComponent
ComponentAttributeExtensionNode - - SomeProp -
HtmlContent - (71:1,40 [3] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (71:1,40 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - val
HtmlContent - (127:3,14 [4] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (127:3,14 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n
HtmlContent - (248:8,1 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (248:8,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
CSharpCode - (143:5,12 [104] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (143:5,12 [104] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private Test.MyComponent myInstance;\n public void Foo() { System.GC.KeepAlive(myInstance); }\n

View File

@ -0,0 +1,21 @@
Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml)
|*, TestAssembly|
Generated Location: (559:16,38 [15] )
|*, TestAssembly|
Source Location: (49:1,18 [10] x:\dir\subdir\Test\TestComponent.cshtml)
|myInstance|
Generated Location: (1202:32,18 [10] )
|myInstance|
Source Location: (143:5,12 [104] x:\dir\subdir\Test\TestComponent.cshtml)
|
private Test.MyComponent myInstance;
public void Foo() { System.GC.KeepAlive(myInstance); }
|
Generated Location: (1386:39,12 [104] )
|
private Test.MyComponent myInstance;
public void Foo() { System.GC.KeepAlive(myInstance); }
|

View File

@ -31,9 +31,8 @@ namespace Test
#pragma warning restore 1998
#line 3 "x:\dir\subdir\Test\TestComponent.cshtml"
Microsoft.AspNetCore.Blazor.ElementRef myElem;
void DoSomething() { myElem.GetHashCode(); } // Avoid 'assigned but not used' warning
private Microsoft.AspNetCore.Blazor.ElementRef myElem;
public void Foo() { System.GC.KeepAlive(myElem); }
#line default
#line hidden

View File

@ -31,7 +31,7 @@ Document -
IntermediateToken - (60:0,60 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - after
HtmlContent - (79:0,79 [4] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (79:0,79 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n
HtmlContent - (243:6,1 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (243:6,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
CSharpCode - (95:2,12 [147] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (95:2,12 [147] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n Microsoft.AspNetCore.Blazor.ElementRef myElem;\n\n void DoSomething() { myElem.GetHashCode(); } // Avoid 'assigned but not used' warning\n
HtmlContent - (214:5,1 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (214:5,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
CSharpCode - (95:2,12 [118] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (95:2,12 [118] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private Microsoft.AspNetCore.Blazor.ElementRef myElem;\n public void Foo() { System.GC.KeepAlive(myElem); }\n

View File

@ -3,16 +3,14 @@ Source Location: (36:0,36 [6] x:\dir\subdir\Test\TestComponent.cshtml)
Generated Location: (956:25,36 [6] )
|myElem|
Source Location: (95:2,12 [147] x:\dir\subdir\Test\TestComponent.cshtml)
Source Location: (95:2,12 [118] x:\dir\subdir\Test\TestComponent.cshtml)
|
Microsoft.AspNetCore.Blazor.ElementRef myElem;
void DoSomething() { myElem.GetHashCode(); } // Avoid 'assigned but not used' warning
private Microsoft.AspNetCore.Blazor.ElementRef myElem;
public void Foo() { System.GC.KeepAlive(myElem); }
|
Generated Location: (1158:32,12 [147] )
Generated Location: (1158:32,12 [118] )
|
Microsoft.AspNetCore.Blazor.ElementRef myElem;
void DoSomething() { myElem.GetHashCode(); } // Avoid 'assigned but not used' warning
private Microsoft.AspNetCore.Blazor.ElementRef myElem;
public void Foo() { System.GC.KeepAlive(myElem); }
|

View File

@ -0,0 +1,37 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
__o = Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue<Microsoft.AspNetCore.Blazor.UIMouseEventArgs>(OnClick);
}
#pragma warning restore 1998
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
void OnClick(UIEventArgs e) {
}
#line default
#line hidden
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,31 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [12] ) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
DesignTimeDirective -
DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor"
DirectiveToken - (14:0,14 [9] ) - "*, Test"
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlElement - (0:0,0 [28] x:\dir\subdir\Test\TestComponent.cshtml) - input
HtmlAttribute - (16:0,16 [8] x:\dir\subdir\Test\TestComponent.cshtml) - onclick=" - "
CSharpExpressionAttributeValue - -
IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue<Microsoft.AspNetCore.Blazor.UIMouseEventArgs>(
IntermediateToken - (17:0,17 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - OnClick
IntermediateToken - - CSharp - )
HtmlContent - (28:0,28 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (28:0,28 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
CSharpCode - (42:1,12 [44] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (42:1,12 [44] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n void OnClick(UIEventArgs e) {\n }\n

View File

@ -0,0 +1,16 @@
Source Location: (17:0,17 [7] x:\dir\subdir\Test\TestComponent.cshtml)
|OnClick|
Generated Location: (1005:24,136 [7] )
|OnClick|
Source Location: (42:1,12 [44] x:\dir\subdir\Test\TestComponent.cshtml)
|
void OnClick(UIEventArgs e) {
}
|
Generated Location: (1128:28,12 [44] )
|
void OnClick(UIEventArgs e) {
}
|

View File

@ -0,0 +1,30 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
__o = Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue<Microsoft.AspNetCore.Blazor.UIMouseEventArgs>(x => { });
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,27 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [12] ) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
DesignTimeDirective -
DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor"
DirectiveToken - (14:0,14 [9] ) - "*, Test"
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlElement - (0:0,0 [31] x:\dir\subdir\Test\TestComponent.cshtml) - input
HtmlAttribute - (16:0,16 [11] x:\dir\subdir\Test\TestComponent.cshtml) - onclick=" - "
CSharpExpressionAttributeValue - -
IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue<Microsoft.AspNetCore.Blazor.UIMouseEventArgs>(
IntermediateToken - (18:0,18 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - x => { }
IntermediateToken - - CSharp - )

View File

@ -0,0 +1,5 @@
Source Location: (18:0,18 [8] x:\dir\subdir\Test\TestComponent.cshtml)
|x => { }|
Generated Location: (1005:24,136 [8] )
|x => { }|

View File

@ -0,0 +1,37 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
__o = Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue<Microsoft.AspNetCore.Blazor.UIMouseEventArgs>(OnClick);
}
#pragma warning restore 1998
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
void OnClick(UIMouseEventArgs e) {
}
#line default
#line hidden
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,31 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [12] ) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
DesignTimeDirective -
DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor"
DirectiveToken - (14:0,14 [9] ) - "*, Test"
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlElement - (0:0,0 [28] x:\dir\subdir\Test\TestComponent.cshtml) - input
HtmlAttribute - (16:0,16 [8] x:\dir\subdir\Test\TestComponent.cshtml) - onclick=" - "
CSharpExpressionAttributeValue - -
IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue<Microsoft.AspNetCore.Blazor.UIMouseEventArgs>(
IntermediateToken - (17:0,17 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - OnClick
IntermediateToken - - CSharp - )
HtmlContent - (28:0,28 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (28:0,28 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
CSharpCode - (42:1,12 [49] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (42:1,12 [49] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n void OnClick(UIMouseEventArgs e) {\n }\n

View File

@ -0,0 +1,16 @@
Source Location: (17:0,17 [7] x:\dir\subdir\Test\TestComponent.cshtml)
|OnClick|
Generated Location: (1005:24,136 [7] )
|OnClick|
Source Location: (42:1,12 [49] x:\dir\subdir\Test\TestComponent.cshtml)
|
void OnClick(UIMouseEventArgs e) {
}
|
Generated Location: (1128:28,12 [49] )
|
void OnClick(UIMouseEventArgs e) {
}
|

View File

@ -0,0 +1,37 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
__o = Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue<Microsoft.AspNetCore.Blazor.UIMouseEventArgs>(OnClick);
}
#pragma warning restore 1998
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
void OnClick() {
}
#line default
#line hidden
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,31 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [12] ) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
DesignTimeDirective -
DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor"
DirectiveToken - (14:0,14 [9] ) - "*, Test"
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlElement - (0:0,0 [28] x:\dir\subdir\Test\TestComponent.cshtml) - input
HtmlAttribute - (16:0,16 [8] x:\dir\subdir\Test\TestComponent.cshtml) - onclick=" - "
CSharpExpressionAttributeValue - -
IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue<Microsoft.AspNetCore.Blazor.UIMouseEventArgs>(
IntermediateToken - (17:0,17 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - OnClick
IntermediateToken - - CSharp - )
HtmlContent - (28:0,28 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (28:0,28 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
CSharpCode - (42:1,12 [31] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (42:1,12 [31] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n void OnClick() {\n }\n

View File

@ -0,0 +1,16 @@
Source Location: (17:0,17 [7] x:\dir\subdir\Test\TestComponent.cshtml)
|OnClick|
Generated Location: (1005:24,136 [7] )
|OnClick|
Source Location: (42:1,12 [31] x:\dir\subdir\Test\TestComponent.cshtml)
|
void OnClick() {
}
|
Generated Location: (1128:28,12 [31] )
|
void OnClick() {
}
|

View File

@ -0,0 +1,30 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
__o = Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue<Microsoft.AspNetCore.Blazor.UIMouseEventArgs>(() => { });
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,27 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [12] ) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
DesignTimeDirective -
DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor"
DirectiveToken - (14:0,14 [9] ) - "*, Test"
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlElement - (0:0,0 [32] x:\dir\subdir\Test\TestComponent.cshtml) - input
HtmlAttribute - (16:0,16 [12] x:\dir\subdir\Test\TestComponent.cshtml) - onclick=" - "
CSharpExpressionAttributeValue - -
IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue<Microsoft.AspNetCore.Blazor.UIMouseEventArgs>(
IntermediateToken - (18:0,18 [9] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - () => { }
IntermediateToken - - CSharp - )

View File

@ -0,0 +1,5 @@
Source Location: (18:0,18 [9] x:\dir\subdir\Test\TestComponent.cshtml)
|() => { }|
Generated Location: (1005:24,136 [9] )
|() => { }|

View File

@ -0,0 +1,34 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = "My value";
#line default
#line hidden
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,28 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [12] ) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
DesignTimeDirective -
DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor"
DirectiveToken - (14:0,14 [9] ) - "*, Test"
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
CSharpExpression - (2:0,2 [10] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (2:0,2 [10] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "My value"
HtmlContent - (13:0,13 [4] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (13:0,13 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n
HtmlElement - (17:2,0 [14] x:\dir\subdir\Test\TestComponent.cshtml) - h1
HtmlContent - (21:2,4 [5] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (21:2,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello

View File

@ -0,0 +1,5 @@
Source Location: (2:0,2 [10] x:\dir\subdir\Test\TestComponent.cshtml)
|"My value"|
Generated Location: (926:25,6 [10] )
|"My value"|

View File

@ -0,0 +1,36 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
((System.Action)(() => {
global::System.Object __typeHelper = "*, TestAssembly";
}
))();
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => {
}
));
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,30 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [12] ) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
DesignTimeDirective -
DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor"
DirectiveToken - (14:0,14 [9] ) - "*, Test"
DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlContent - (29:0,29 [7] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (29:0,29 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n \n
ComponentExtensionNode - (36:2,0 [22] x:\dir\subdir\Test\TestComponent.cshtml) - SomeOtherComponent - Test.SomeOtherComponent
HtmlContent - (58:2,22 [4] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (58:2,22 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n
HtmlElement - (62:4,0 [14] x:\dir\subdir\Test\TestComponent.cshtml) - h1
HtmlContent - (66:4,4 [5] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (66:4,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello

View File

@ -0,0 +1,5 @@
Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml)
|*, TestAssembly|
Generated Location: (559:16,38 [15] )
|*, TestAssembly|

View File

@ -0,0 +1,33 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
using System;
#line default
#line hidden
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,26 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (1:0,1 [12] x:\dir\subdir\Test\TestComponent.cshtml) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
DesignTimeDirective -
DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor"
DirectiveToken - (14:0,14 [9] ) - "*, Test"
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlContent - (13:0,13 [4] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (13:0,13 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n
HtmlElement - (17:2,0 [14] x:\dir\subdir\Test\TestComponent.cshtml) - h1
HtmlContent - (21:2,4 [5] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (21:2,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello

View File

@ -0,0 +1,5 @@
Source Location: (1:0,1 [12] x:\dir\subdir\Test\TestComponent.cshtml)
|using System|
Generated Location: (140:6,0 [12] )
|using System|

View File

@ -0,0 +1,44 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
((System.Action)(() => {
global::System.Object __typeHelper = "*, TestAssembly";
}
))();
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.AddAttribute(-1, "Header", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => {
}
));
builder.AddAttribute(-1, "Footer", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => {
#line 4 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = "bye!";
#line default
#line hidden
}
));
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,31 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [12] ) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
DesignTimeDirective -
DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor"
DirectiveToken - (14:0,14 [9] ) - "*, Test"
DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
ComponentExtensionNode - (31:1,0 [87] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent
ComponentChildContent - (50:2,4 [20] x:\dir\subdir\Test\TestComponent.cshtml) - Header
HtmlContent - (58:2,12 [3] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (58:2,12 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hi!
ComponentChildContent - (76:3,4 [26] x:\dir\subdir\Test\TestComponent.cshtml) - Footer
CSharpExpression - (86:3,14 [6] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (86:3,14 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "bye!"

View File

@ -0,0 +1,10 @@
Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml)
|*, TestAssembly|
Generated Location: (559:16,38 [15] )
|*, TestAssembly|
Source Location: (86:3,14 [6] x:\dir\subdir\Test\TestComponent.cshtml)
|"bye!"|
Generated Location: (1301:33,14 [6] )
|"bye!"|

View File

@ -31,7 +31,7 @@ global::System.Object __typeHelper = "*, TestAssembly";
#line default
#line hidden
(builder2, context) => {
(builder2) => {
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = context.Name;

View File

@ -10,16 +10,16 @@ Generated Location: (1039:29,2 [35] )
Source Location: (77:1,44 [12] x:\dir\subdir\Test\TestComponent.cshtml)
|context.Name|
Generated Location: (1240:35,44 [12] )
Generated Location: (1231:35,44 [12] )
|context.Name|
Source Location: (95:1,62 [2] x:\dir\subdir\Test\TestComponent.cshtml)
|; |
Generated Location: (1414:41,62 [2] )
Generated Location: (1405:41,62 [2] )
|; |
Source Location: (130:2,30 [8] x:\dir\subdir\Test\TestComponent.cshtml)
|template|
Generated Location: (1610:47,30 [8] )
Generated Location: (1601:47,30 [8] )
|template|

View File

@ -27,24 +27,24 @@ global::System.Object __typeHelper = "*, TestAssembly";
{
base.BuildRenderTree(builder);
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
RenderFragment<Test.Context> template =
RenderFragment<Test.Context> template = (context) =>
#line default
#line hidden
(builder2, context) => {
(builder2) => {
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = context.Index;
__o = context.Index;
#line default
#line hidden
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = context.Item.ToLower();
__o = context.Item.ToLower();
#line default
#line hidden
}
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
;
;
#line default
#line hidden

Some files were not shown because too many files have changed in this diff Show More