diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDesignTimeNodeWriter.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDesignTimeNodeWriter.cs index 4553b0da03..d067eebc63 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDesignTimeNodeWriter.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDesignTimeNodeWriter.cs @@ -417,16 +417,30 @@ namespace Microsoft.AspNetCore.Blazor.Razor } else { - // This is the case when an attribute has an explicit C# transition like: - // + // 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(); } diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorRuntimeNodeWriter.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorRuntimeNodeWriter.cs index 79e6a2fb02..b91431ad1b 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorRuntimeNodeWriter.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorRuntimeNodeWriter.cs @@ -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(")"); + } } } diff --git a/src/Microsoft.AspNetCore.Blazor/Components/RuntimeHelpers.cs b/src/Microsoft.AspNetCore.Blazor/Components/RuntimeHelpers.cs new file mode 100644 index 0000000000..4433077039 --- /dev/null +++ b/src/Microsoft.AspNetCore.Blazor/Components/RuntimeHelpers.cs @@ -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 +{ + /// + /// Used by generated code produced by the Blazor code generator. Not intended or supported + /// for use in application code. + /// + public static class RuntimeHelpers + { + /// + /// Not intended for use by application code. + /// + /// + /// + /// + public static T TypeCheck(T value) => value; + } +} diff --git a/src/shared/BlazorApi.cs b/src/shared/BlazorApi.cs index d66402b110..d9f07f9993 100644 --- a/src/shared/BlazorApi.cs +++ b/src/shared/BlazorApi.cs @@ -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"; diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/DesignTimeCodeGenerationTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/DesignTimeCodeGenerationTest.cs index 4f5bb5d20f..2832cb83e5 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/DesignTimeCodeGenerationTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/DesignTimeCodeGenerationTest.cs @@ -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 + +"); + + // 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 ValueChanged { get; set; } + } +}")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +@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() { diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/RuntimeCodeGenerationTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/RuntimeCodeGenerationTest.cs index c2af00e283..d57e1bcb91 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/RuntimeCodeGenerationTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/RuntimeCodeGenerationTest.cs @@ -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 + +"); + + // 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() { diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties/TestComponent.codegen.cs index 0aa21b325d..addfe4f2b0 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties/TestComponent.codegen.cs @@ -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(Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" ParentValue #line default #line hidden - ); + )); __o = new System.Action( __value => ParentValue = __value); builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties/TestComponent.mappings.txt index ffb9e32933..3d978c338f 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties/TestComponent.mappings.txt @@ -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; | diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_SpecifiesValue_WithMatchingProperties/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_SpecifiesValue_WithMatchingProperties/TestComponent.codegen.cs index c584e9ac06..ec158033c8 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_SpecifiesValue_WithMatchingProperties/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_SpecifiesValue_WithMatchingProperties/TestComponent.codegen.cs @@ -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(Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" ParentValue #line default #line hidden - ); + )); __o = new System.Action( __value => ParentValue = __value); builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_SpecifiesValue_WithMatchingProperties/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_SpecifiesValue_WithMatchingProperties/TestComponent.mappings.txt index 5e04897752..d185903a98 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_SpecifiesValue_WithMatchingProperties/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_SpecifiesValue_WithMatchingProperties/TestComponent.mappings.txt @@ -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; | diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_TypeChecked_WithMatchingProperties/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_TypeChecked_WithMatchingProperties/TestComponent.codegen.cs new file mode 100644 index 0000000000..e84b426047 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_TypeChecked_WithMatchingProperties/TestComponent.codegen.cs @@ -0,0 +1,51 @@ +// +#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(Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + ParentValue + +#line default +#line hidden + )); + __o = new System.Action( + __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 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_TypeChecked_WithMatchingProperties/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_TypeChecked_WithMatchingProperties/TestComponent.ir.txt new file mode 100644 index 0000000000..836a9a60df --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_TypeChecked_WithMatchingProperties/TestComponent.ir.txt @@ -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 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_TypeChecked_WithMatchingProperties/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_TypeChecked_WithMatchingProperties/TestComponent.mappings.txt new file mode 100644 index 0000000000..be8d4cbc02 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BindToComponent_TypeChecked_WithMatchingProperties/TestComponent.mappings.txt @@ -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"; +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitStringParameter/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitStringParameter/TestComponent.codegen.cs index 46c0a9d442..6987842070 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitStringParameter/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitStringParameter/TestComponent.codegen.cs @@ -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( #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" 42.ToString() #line default #line hidden - ; + ); builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { } )); diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitStringParameter/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitStringParameter/TestComponent.mappings.txt index 3795536c85..ce035f8168 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitStringParameter/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitStringParameter/TestComponent.mappings.txt @@ -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()| diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.codegen.cs index ff8f313ae3..ef017e32b0 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.codegen.cs @@ -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( #line 3 "x:\dir\subdir\Test\TestComponent.cshtml" 123 #line default #line hidden - ; - __o = + ); + __o = Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck( #line 4 "x:\dir\subdir\Test\TestComponent.cshtml" true #line default #line hidden - ; - __o = + ); + __o = Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck( #line 6 "x:\dir\subdir\Test\TestComponent.cshtml" new SomeType() #line default #line hidden - ; + ); builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { } )); diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.mappings.txt index a8fd859264..c5335f3026 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.mappings.txt @@ -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()| diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ComponentParameter_TypeMismatch_ReportsDiagnostic/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ComponentParameter_TypeMismatch_ReportsDiagnostic/TestComponent.codegen.cs new file mode 100644 index 0000000000..b2ce5612e9 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ComponentParameter_TypeMismatch_ReportsDiagnostic/TestComponent.codegen.cs @@ -0,0 +1,43 @@ +// +#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( +#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 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ComponentParameter_TypeMismatch_ReportsDiagnostic/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ComponentParameter_TypeMismatch_ReportsDiagnostic/TestComponent.ir.txt new file mode 100644 index 0000000000..20f0a9c4b0 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ComponentParameter_TypeMismatch_ReportsDiagnostic/TestComponent.ir.txt @@ -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 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ComponentParameter_TypeMismatch_ReportsDiagnostic/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ComponentParameter_TypeMismatch_ReportsDiagnostic/TestComponent.mappings.txt new file mode 100644 index 0000000000..23d1a88d35 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ComponentParameter_TypeMismatch_ReportsDiagnostic/TestComponent.mappings.txt @@ -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"| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties/TestComponent.codegen.cs index d767e389e4..cf84e1266c 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties/TestComponent.codegen.cs @@ -16,7 +16,7 @@ namespace Test { base.BuildRenderTree(builder); builder.OpenComponent(0); - builder.AddAttribute(1, "Value", Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(ParentValue)); + builder.AddAttribute(1, "Value", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck(Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(ParentValue))); builder.AddAttribute(2, "OnChanged", new System.Action(__value => ParentValue = __value)); builder.CloseComponent(); } diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties/TestComponent.mappings.txt index 04949b16f7..630daead81 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties/TestComponent.mappings.txt @@ -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; | diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_SpecifiesValue_WithMatchingProperties/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_SpecifiesValue_WithMatchingProperties/TestComponent.codegen.cs index 8e2f3055d5..cb38bfe838 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_SpecifiesValue_WithMatchingProperties/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_SpecifiesValue_WithMatchingProperties/TestComponent.codegen.cs @@ -16,7 +16,7 @@ namespace Test { base.BuildRenderTree(builder); builder.OpenComponent(0); - builder.AddAttribute(1, "Value", Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(ParentValue)); + builder.AddAttribute(1, "Value", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck(Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(ParentValue))); builder.AddAttribute(2, "ValueChanged", new System.Action(__value => ParentValue = __value)); builder.CloseComponent(); } diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_SpecifiesValue_WithMatchingProperties/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_SpecifiesValue_WithMatchingProperties/TestComponent.mappings.txt index 9b93868d29..726cf8cc3b 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_SpecifiesValue_WithMatchingProperties/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_SpecifiesValue_WithMatchingProperties/TestComponent.mappings.txt @@ -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; | diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_TypeChecked_WithMatchingProperties/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_TypeChecked_WithMatchingProperties/TestComponent.codegen.cs new file mode 100644 index 0000000000..2ac3407cac --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_TypeChecked_WithMatchingProperties/TestComponent.codegen.cs @@ -0,0 +1,32 @@ +// +#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(0); + builder.AddAttribute(1, "Value", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck(Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(ParentValue))); + builder.AddAttribute(2, "ValueChanged", new System.Action(__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 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_TypeChecked_WithMatchingProperties/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_TypeChecked_WithMatchingProperties/TestComponent.ir.txt new file mode 100644 index 0000000000..897419409e --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_TypeChecked_WithMatchingProperties/TestComponent.ir.txt @@ -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 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_TypeChecked_WithMatchingProperties/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_TypeChecked_WithMatchingProperties/TestComponent.mappings.txt new file mode 100644 index 0000000000..33f399176b --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BindToComponent_TypeChecked_WithMatchingProperties/TestComponent.mappings.txt @@ -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"; +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithExplicitStringParameter/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithExplicitStringParameter/TestComponent.codegen.cs index 723f0b72e9..81c7775131 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithExplicitStringParameter/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithExplicitStringParameter/TestComponent.codegen.cs @@ -16,7 +16,7 @@ namespace Test { base.BuildRenderTree(builder); builder.OpenComponent(0); - builder.AddAttribute(1, "StringProperty", 42.ToString()); + builder.AddAttribute(1, "StringProperty", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck(42.ToString())); builder.CloseComponent(); } #pragma warning restore 1998 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.codegen.cs index 5baa09463a..16b1ff675a 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.codegen.cs @@ -16,10 +16,10 @@ namespace Test { base.BuildRenderTree(builder); builder.OpenComponent(0); - builder.AddAttribute(1, "IntProperty", 123); - builder.AddAttribute(2, "BoolProperty", true); + builder.AddAttribute(1, "IntProperty", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck(123)); + builder.AddAttribute(2, "BoolProperty", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck(true)); builder.AddAttribute(3, "StringProperty", "My string"); - builder.AddAttribute(4, "ObjectProperty", new SomeType()); + builder.AddAttribute(4, "ObjectProperty", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck(new SomeType())); builder.CloseComponent(); } #pragma warning restore 1998 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ComponentParameter_TypeMismatch_ReportsDiagnostic/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ComponentParameter_TypeMismatch_ReportsDiagnostic/TestComponent.codegen.cs new file mode 100644 index 0000000000..6bbff7fb13 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ComponentParameter_TypeMismatch_ReportsDiagnostic/TestComponent.codegen.cs @@ -0,0 +1,25 @@ +// +#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(0); + builder.AddAttribute(1, "Coolness", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck("very-cool")); + builder.CloseComponent(); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ComponentParameter_TypeMismatch_ReportsDiagnostic/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ComponentParameter_TypeMismatch_ReportsDiagnostic/TestComponent.ir.txt new file mode 100644 index 0000000000..0652ded440 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ComponentParameter_TypeMismatch_ReportsDiagnostic/TestComponent.ir.txt @@ -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"