Add type checking for component parameters

Introduces a new primitive used by the compiler for type checking. Type
checking applies to component parameters when setting the value directly
and when using bind. This is nice because it also adds error checking
for bind.
This commit is contained in:
Ryan Nowak 2018-06-05 09:09:41 -07:00
parent 5cb544ece8
commit cb186f494a
31 changed files with 486 additions and 31 deletions

View File

@ -417,16 +417,30 @@ namespace Microsoft.AspNetCore.Blazor.Razor
}
else
{
// This is the case when an attribute has an explicit C# transition like:
// <MyComponent Foo="@bar" />
// This is the case when an attribute contains C# code
context.CodeWriter.Write(DesignTimeVariable);
context.CodeWriter.Write(" = ");
// If we have a parameter type, then add a type check.
if (node.BoundAttribute != null)
{
context.CodeWriter.Write(BlazorApi.RuntimeHelpers.TypeCheck);
context.CodeWriter.Write("<");
context.CodeWriter.Write(node.BoundAttribute.TypeName);
context.CodeWriter.Write(">");
context.CodeWriter.Write("(");
}
for (var i = 0; i < tokens.Count; i++)
{
WriteCSharpToken(context, tokens[i]);
}
if (node.BoundAttribute != null)
{
context.CodeWriter.Write(")");
}
context.CodeWriter.Write(";");
context.CodeWriter.WriteLine();
}

View File

@ -379,10 +379,24 @@ namespace Microsoft.AspNetCore.Blazor.Razor
}
else
{
if (node.BoundAttribute != null)
{
context.CodeWriter.Write(BlazorApi.RuntimeHelpers.TypeCheck);
context.CodeWriter.Write("<");
context.CodeWriter.Write(node.BoundAttribute.TypeName);
context.CodeWriter.Write(">");
context.CodeWriter.Write("(");
}
for (var i = 0; i < tokens.Count; i++)
{
context.CodeWriter.Write(tokens[i].Content);
}
if (node.BoundAttribute != null)
{
context.CodeWriter.Write(")");
}
}
}

View File

@ -0,0 +1,21 @@
// 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.Components
{
/// <summary>
/// Used by generated code produced by the Blazor code generator. Not intended or supported
/// for use in application code.
/// </summary>
public static class RuntimeHelpers
{
/// <summary>
/// Not intended for use by application code.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value"></param>
/// <returns></returns>
public static T TypeCheck<T>(T value) => value;
}
}

View File

@ -72,6 +72,11 @@ namespace Microsoft.AspNetCore.Blazor.Shared
public static readonly string ChildContent = nameof(ChildContent);
}
public static class RuntimeHelpers
{
public static readonly string TypeCheck = "Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck";
}
public static class RouteAttribute
{
public static readonly string FullTypeName = "Microsoft.AspNetCore.Blazor.Components.RouteAttribute";

View File

@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
internal override bool DesignTime => true;
internal override bool UseTwoPhaseCompilation => true;
[Fact]
public void ChildComponent_WithParameters()
{
@ -50,6 +50,39 @@ namespace Test
CompileToAssembly(generated);
}
[Fact]
public void ComponentParameter_TypeMismatch_ReportsDiagnostic()
{
// Arrange
AdditionalSyntaxTrees.Add(Parse(@"
using Microsoft.AspNetCore.Blazor.Components;
namespace Test
{
public class CoolnessMeter : BlazorComponent
{
[Parameter] private int Coolness { get; set; }
}
}
"));
// Act
var generated = CompileToCSharp(@"
@addTagHelper *, TestAssembly
<CoolnessMeter Coolness=""@(""very-cool"")"" />
");
// Assert
AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
var assembly = CompileToAssembly(generated, throwOnFailure: false);
// This has some errors
Assert.Collection(
assembly.Diagnostics.OrderBy(d => d.Id),
d => Assert.Equal("CS1503", d.Id));
}
[Fact]
public void ChildComponent_WithExplicitStringParameter()
{
@ -564,6 +597,46 @@ namespace Test
CompileToAssembly(generated);
}
[Fact]
public void BindToComponent_TypeChecked_WithMatchingProperties()
{
// Arrange
AdditionalSyntaxTrees.Add(Parse(@"
using System;
using Microsoft.AspNetCore.Blazor.Components;
namespace Test
{
public class MyComponent : BlazorComponent
{
[Parameter]
int Value { get; set; }
[Parameter]
Action<int> ValueChanged { get; set; }
}
}"));
// Act
var generated = CompileToCSharp(@"
@addTagHelper *, TestAssembly
<MyComponent bind-Value=""ParentValue"" />
@functions {
public string ParentValue { get; set; } = ""42"";
}");
// Assert
AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
var assembly = CompileToAssembly(generated, throwOnFailure: false);
// This has some errors
Assert.Collection(
assembly.Diagnostics.OrderBy(d => d.Id),
d => Assert.Equal("CS0029", d.Id),
d => Assert.Equal("CS1503", d.Id));
}
[Fact]
public void BindToComponent_SpecifiesValue_WithoutMatchingProperties()
{

View File

@ -292,6 +292,39 @@ namespace Test
CompileToAssembly(generated);
}
[Fact]
public void ComponentParameter_TypeMismatch_ReportsDiagnostic()
{
// Arrange
AdditionalSyntaxTrees.Add(Parse(@"
using Microsoft.AspNetCore.Blazor.Components;
namespace Test
{
public class CoolnessMeter : BlazorComponent
{
[Parameter] private int Coolness { get; set; }
}
}
"));
// Act
var generated = CompileToCSharp(@"
@addTagHelper *, TestAssembly
<CoolnessMeter Coolness=""@(""very-cool"")"" />
");
// Assert
AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
var assembly = CompileToAssembly(generated, throwOnFailure: false);
// This has some errors
Assert.Collection(
assembly.Diagnostics.OrderBy(d => d.Id),
d => Assert.Equal("CS1503", d.Id));
}
[Fact]
public void EventHandler_OnElement_WithString()
{

View File

@ -26,13 +26,13 @@ global::System.Object __typeHelper = "*, TestAssembly";
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
__o = Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(
__o = Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck<System.Int32>(Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
ParentValue
#line default
#line hidden
);
));
__o = new System.Action<System.Int32>(
__value => ParentValue = __value);
builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => {

View File

@ -5,14 +5,14 @@ Generated Location: (559:16,38 [15] )
Source Location: (66:1,35 [11] x:\dir\subdir\Test\TestComponent.cshtml)
|ParentValue|
Generated Location: (1152:30,35 [11] )
Generated Location: (1230:30,35 [11] )
|ParentValue|
Source Location: (95:2,12 [50] x:\dir\subdir\Test\TestComponent.cshtml)
|
public int ParentValue { get; set; } = 42;
|
Generated Location: (1571:43,12 [50] )
Generated Location: (1650:43,12 [50] )
|
public int ParentValue { get; set; } = 42;
|

View File

@ -26,13 +26,13 @@ global::System.Object __typeHelper = "*, TestAssembly";
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
__o = Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(
__o = Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck<System.Int32>(Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
ParentValue
#line default
#line hidden
);
));
__o = new System.Action<System.Int32>(
__value => ParentValue = __value);
builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => {

View File

@ -5,14 +5,14 @@ Generated Location: (559:16,38 [15] )
Source Location: (56:1,25 [11] x:\dir\subdir\Test\TestComponent.cshtml)
|ParentValue|
Generated Location: (1142:30,25 [11] )
Generated Location: (1220:30,25 [11] )
|ParentValue|
Source Location: (85:2,12 [50] x:\dir\subdir\Test\TestComponent.cshtml)
|
public int ParentValue { get; set; } = 42;
|
Generated Location: (1561:43,12 [50] )
Generated Location: (1640:43,12 [50] )
|
public int ParentValue { get; set; } = 42;
|

View File

@ -0,0 +1,51 @@
// <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);
__o = Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck<System.Int32>(Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
ParentValue
#line default
#line hidden
));
__o = new System.Action<System.Int32>(
__value => ParentValue = __value);
builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => {
}
));
}
#pragma warning restore 1998
#line 3 "x:\dir\subdir\Test\TestComponent.cshtml"
public string ParentValue { get; set; } = "42";
#line default
#line hidden
}
}
#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 [40] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent
ComponentAttributeExtensionNode - (56:1,25 [11] x:\dir\subdir\Test\TestComponent.cshtml) - Value - Value
CSharpExpression -
IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(
IntermediateToken - (56:1,25 [11] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ParentValue
IntermediateToken - - CSharp - )
ComponentAttributeExtensionNode - (56:1,25 [11] x:\dir\subdir\Test\TestComponent.cshtml) - ValueChanged - ValueChanged
CSharpExpression -
IntermediateToken - - CSharp - __value => ParentValue = __value
HtmlContent - (71:1,40 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (71:1,40 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
CSharpCode - (85:2,12 [55] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (85:2,12 [55] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n public string ParentValue { get; set; } = "42";\n

View File

@ -0,0 +1,19 @@
Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml)
|*, TestAssembly|
Generated Location: (559:16,38 [15] )
|*, TestAssembly|
Source Location: (56:1,25 [11] x:\dir\subdir\Test\TestComponent.cshtml)
|ParentValue|
Generated Location: (1220:30,25 [11] )
|ParentValue|
Source Location: (85:2,12 [55] x:\dir\subdir\Test\TestComponent.cshtml)
|
public string ParentValue { get; set; } = "42";
|
Generated Location: (1640:43,12 [55] )
|
public string ParentValue { get; set; } = "42";
|

View File

@ -26,13 +26,13 @@ global::System.Object __typeHelper = "*, TestAssembly";
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
__o =
__o = Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck<System.String>(
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
42.ToString()
#line default
#line hidden
;
);
builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => {
}
));

View File

@ -5,6 +5,6 @@ Generated Location: (559:16,38 [15] )
Source Location: (62:1,31 [13] x:\dir\subdir\Test\TestComponent.cshtml)
|42.ToString()|
Generated Location: (1088:30,31 [13] )
Generated Location: (1167:30,31 [13] )
|42.ToString()|

View File

@ -26,27 +26,27 @@ global::System.Object __typeHelper = "*, TestAssembly";
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
__o =
__o = Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck<System.Int32>(
#line 3 "x:\dir\subdir\Test\TestComponent.cshtml"
123
#line default
#line hidden
;
__o =
);
__o = Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck<System.Boolean>(
#line 4 "x:\dir\subdir\Test\TestComponent.cshtml"
true
#line default
#line hidden
;
__o =
);
__o = Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck<Test.SomeType>(
#line 6 "x:\dir\subdir\Test\TestComponent.cshtml"
new SomeType()
#line default
#line hidden
;
);
builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => {
}
));

View File

@ -5,16 +5,16 @@ Generated Location: (559:16,38 [15] )
Source Location: (63:2,17 [3] x:\dir\subdir\Test\TestComponent.cshtml)
|123|
Generated Location: (1074:30,17 [3] )
Generated Location: (1152:30,17 [3] )
|123|
Source Location: (87:3,18 [4] x:\dir\subdir\Test\TestComponent.cshtml)
|true|
Generated Location: (1214:37,18 [4] )
Generated Location: (1373:37,18 [4] )
|true|
Source Location: (146:5,20 [14] x:\dir\subdir\Test\TestComponent.cshtml)
|new SomeType()|
Generated Location: (1357:44,20 [14] )
Generated Location: (1596:44,20 [14] )
|new SomeType()|

View File

@ -0,0 +1,43 @@
// <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);
__o = Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck<System.Int32>(
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
"very-cool"
#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,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 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
ComponentExtensionNode - (31:1,0 [43] x:\dir\subdir\Test\TestComponent.cshtml) - CoolnessMeter - Test.CoolnessMeter
ComponentAttributeExtensionNode - (56:1,25 [14] x:\dir\subdir\Test\TestComponent.cshtml) - Coolness - Coolness
CSharpExpression - (57:1,26 [13] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (58:1,27 [11] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "very-cool"
HtmlContent - (74:1,43 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (74:1,43 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n

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: (58:1,27 [11] x:\dir\subdir\Test\TestComponent.cshtml)
|"very-cool"|
Generated Location: (1162:30,27 [11] )
|"very-cool"|

View File

@ -16,7 +16,7 @@ namespace Test
{
base.BuildRenderTree(builder);
builder.OpenComponent<Test.MyComponent>(0);
builder.AddAttribute(1, "Value", Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(ParentValue));
builder.AddAttribute(1, "Value", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck<System.Int32>(Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(ParentValue)));
builder.AddAttribute(2, "OnChanged", new System.Action<System.Int32>(__value => ParentValue = __value));
builder.CloseComponent();
}

View File

@ -2,7 +2,7 @@ Source Location: (95:2,12 [50] x:\dir\subdir\Test\TestComponent.cshtml)
|
public int ParentValue { get; set; } = 42;
|
Generated Location: (1048:24,12 [50] )
Generated Location: (1127:24,12 [50] )
|
public int ParentValue { get; set; } = 42;
|

View File

@ -16,7 +16,7 @@ namespace Test
{
base.BuildRenderTree(builder);
builder.OpenComponent<Test.MyComponent>(0);
builder.AddAttribute(1, "Value", Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(ParentValue));
builder.AddAttribute(1, "Value", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck<System.Int32>(Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(ParentValue)));
builder.AddAttribute(2, "ValueChanged", new System.Action<System.Int32>(__value => ParentValue = __value));
builder.CloseComponent();
}

View File

@ -2,7 +2,7 @@ Source Location: (85:2,12 [50] x:\dir\subdir\Test\TestComponent.cshtml)
|
public int ParentValue { get; set; } = 42;
|
Generated Location: (1051:24,12 [50] )
Generated Location: (1130:24,12 [50] )
|
public int ParentValue { get; set; } = 42;
|

View File

@ -0,0 +1,32 @@
// <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 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.OpenComponent<Test.MyComponent>(0);
builder.AddAttribute(1, "Value", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck<System.Int32>(Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(ParentValue)));
builder.AddAttribute(2, "ValueChanged", new System.Action<System.Int32>(__value => ParentValue = __value));
builder.CloseComponent();
}
#pragma warning restore 1998
#line 3 "x:\dir\subdir\Test\TestComponent.cshtml"
public string ParentValue { get; set; } = "42";
#line default
#line hidden
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,23 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [14] ) - System
UsingDirective - (18:2,1 [34] ) - System.Collections.Generic
UsingDirective - (53:3,1 [19] ) - System.Linq
UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
ComponentExtensionNode - (31:1,0 [40] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent
ComponentAttributeExtensionNode - (56:1,25 [11] x:\dir\subdir\Test\TestComponent.cshtml) - Value - Value
CSharpExpression -
IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(
IntermediateToken - (56:1,25 [11] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ParentValue
IntermediateToken - - CSharp - )
ComponentAttributeExtensionNode - (56:1,25 [11] x:\dir\subdir\Test\TestComponent.cshtml) - ValueChanged - ValueChanged
CSharpExpression -
IntermediateToken - - CSharp - __value => ParentValue = __value
CSharpCode - (85:2,12 [55] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (85:2,12 [55] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n public string ParentValue { get; set; } = "42";\n

View File

@ -0,0 +1,9 @@
Source Location: (85:2,12 [55] x:\dir\subdir\Test\TestComponent.cshtml)
|
public string ParentValue { get; set; } = "42";
|
Generated Location: (1130:24,12 [55] )
|
public string ParentValue { get; set; } = "42";
|

View File

@ -16,7 +16,7 @@ namespace Test
{
base.BuildRenderTree(builder);
builder.OpenComponent<Test.MyComponent>(0);
builder.AddAttribute(1, "StringProperty", 42.ToString());
builder.AddAttribute(1, "StringProperty", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck<System.String>(42.ToString()));
builder.CloseComponent();
}
#pragma warning restore 1998

View File

@ -16,10 +16,10 @@ namespace Test
{
base.BuildRenderTree(builder);
builder.OpenComponent<Test.MyComponent>(0);
builder.AddAttribute(1, "IntProperty", 123);
builder.AddAttribute(2, "BoolProperty", true);
builder.AddAttribute(1, "IntProperty", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck<System.Int32>(123));
builder.AddAttribute(2, "BoolProperty", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck<System.Boolean>(true));
builder.AddAttribute(3, "StringProperty", "My string");
builder.AddAttribute(4, "ObjectProperty", new SomeType());
builder.AddAttribute(4, "ObjectProperty", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck<Test.SomeType>(new SomeType()));
builder.CloseComponent();
}
#pragma warning restore 1998

View File

@ -0,0 +1,25 @@
// <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 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.OpenComponent<Test.CoolnessMeter>(0);
builder.AddAttribute(1, "Coolness", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck<System.Int32>("very-cool"));
builder.CloseComponent();
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591

View File

@ -0,0 +1,16 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [14] ) - System
UsingDirective - (18:2,1 [34] ) - System.Collections.Generic
UsingDirective - (53:3,1 [19] ) - System.Linq
UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor
UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent -
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
ComponentExtensionNode - (31:1,0 [43] x:\dir\subdir\Test\TestComponent.cshtml) - CoolnessMeter - Test.CoolnessMeter
ComponentAttributeExtensionNode - (56:1,25 [14] x:\dir\subdir\Test\TestComponent.cshtml) - Coolness - Coolness
CSharpExpression - (57:1,26 [13] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (58:1,27 [11] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "very-cool"