Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Match component properties as case insensitive #10657

Merged
merged 11 commits into from
Jul 26, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,93 @@ public class MyComponent<T> : ComponentBase
CompileToAssembly(generated);
}

[IntegrationTestFact, WorkItem("https://github.com/dotnet/aspnetcore/issues/48778")]
public void ImplicitStringConversion_ParameterCasing_AddAttribute()
{
_configuration = base.Configuration with { LanguageVersion = RazorLanguageVersion.Version_7_0 };

AdditionalSyntaxTrees.Add(Parse("""
using Microsoft.AspNetCore.Components;

namespace Test;

public class MyClass
{
public static implicit operator string(MyClass c) => "";
}

public class MyComponent : ComponentBase
{
[Parameter] public string Placeholder { get; set; } = "";
}
"""));

var generated = CompileToCSharp("""
<MyComponent PlaceHolder="@(new MyClass())" />
""");

AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
CompileToAssembly(generated);
}

[IntegrationTestFact, WorkItem("https://github.com/dotnet/aspnetcore/issues/48778")]
public void ImplicitStringConversion_ParameterCasing_AddComponentParameter()
{
AdditionalSyntaxTrees.Add(Parse("""
using Microsoft.AspNetCore.Components;

namespace Test;

public class MyClass
{
public static implicit operator string(MyClass c) => "";
}

public class MyComponent : ComponentBase
{
[Parameter] public string Placeholder { get; set; } = "";
}
"""));

var generated = CompileToCSharp("""
<MyComponent PlaceHolder="@(new MyClass())" />
""");

AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
CompileToAssembly(generated);
}

[IntegrationTestFact, WorkItem("https://github.com/dotnet/aspnetcore/issues/48778")]
public void ImplicitStringConversion_ParameterCasing_Multiple()
{
AdditionalSyntaxTrees.Add(Parse("""
using Microsoft.AspNetCore.Components;

namespace Test;

public class MyClass
{
public static implicit operator string(MyClass c) => "";
}

public class MyComponent : ComponentBase
{
[Parameter] public string Placeholder { get; set; } = "";
[Parameter] public string PlaceHolder { get; set; } = "";
}
"""));

var generated = CompileToCSharp("""
<MyComponent PlaceHolder="@(new MyClass())" />
""");

AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
CompileToAssembly(generated);
}

[IntegrationTestFact, WorkItem("https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1869483")]
public void AddComponentParameter()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line default
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
__o = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.String>(
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
new MyClass()

#line default
#line hidden
#nullable disable
);
__builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => {
}
));
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = typeof(global::Test.MyComponent);

#line default
#line hidden
#nullable disable
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [20] ) - global::System
UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
UsingDirective - (69:3,1 [25] ) - global::System.Linq
UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
Component - (0:0,0 [46] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent
ComponentAttribute - (26:0,26 [16] x:\dir\subdir\Test\TestComponent.cshtml) - PlaceHolder - Placeholder - AttributeStructure.DoubleQuotes
CSharpExpression - (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - new MyClass()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Source Location: (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml)
|new MyClass()|
Generated Location: (1138:29,28 [13] )
|new MyClass()|

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line default
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
__o = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.String>(
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
new MyClass()

#line default
#line hidden
#nullable disable
);
__builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => {
}
));
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = typeof(global::Test.MyComponent);

#line default
#line hidden
#nullable disable
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [20] ) - global::System
UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
UsingDirective - (69:3,1 [25] ) - global::System.Linq
UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
Component - (0:0,0 [46] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent
ComponentAttribute - (26:0,26 [16] x:\dir\subdir\Test\TestComponent.cshtml) - PlaceHolder - Placeholder - AttributeStructure.DoubleQuotes
CSharpExpression - (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - new MyClass()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Source Location: (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml)
|new MyClass()|
Generated Location: (1138:29,28 [13] )
|new MyClass()|

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line default
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
__o = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.String>(
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
new MyClass()

#line default
#line hidden
#nullable disable
);
__builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => {
}
));
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = typeof(global::Test.MyComponent);

#line default
#line hidden
#nullable disable
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [20] ) - global::System
UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
UsingDirective - (69:3,1 [25] ) - global::System.Linq
UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
Component - (0:0,0 [46] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent
ComponentAttribute - (26:0,26 [16] x:\dir\subdir\Test\TestComponent.cshtml) - PlaceHolder - Placeholder - AttributeStructure.DoubleQuotes
CSharpExpression - (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - new MyClass()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Source Location: (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml)
|new MyClass()|
Generated Location: (1138:29,28 [13] )
|new MyClass()|

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line default
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
__builder.OpenComponent<global::Test.MyComponent>(0);
__builder.AddAttribute(1, nameof(global::Test.MyComponent.
#nullable restore
#line (1,14)-(1,25) "x:\dir\subdir\Test\TestComponent.cshtml"
Placeholder

#line default
#line hidden
#nullable disable
), (object)(global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.String>(
#nullable restore
#line (1,29)-(1,42) "x:\dir\subdir\Test\TestComponent.cshtml"
new MyClass()

#line default
#line hidden
#nullable disable
)));
__builder.CloseComponent();
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [22] ) - global::System
UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
UsingDirective - (69:3,1 [27] ) - global::System.Linq
UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
MethodDeclaration - - protected override - void - BuildRenderTree
Component - (0:0,0 [46] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent
ComponentAttribute - (26:0,26 [16] x:\dir\subdir\Test\TestComponent.cshtml) - PlaceHolder - Placeholder - AttributeStructure.DoubleQuotes
CSharpExpression - (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - new MyClass()
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Source Location: (13:0,13 [11] x:\dir\subdir\Test\TestComponent.cshtml)
|PlaceHolder|
Generated Location: (875:23,0 [11] )
|Placeholder|

Source Location: (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml)
|new MyClass()|
Generated Location: (1151:31,0 [13] )
|new MyClass()|

Loading