Skip to content
This repository was archived by the owner on Feb 25, 2021. It is now read-only.

Commit 1746ff2

Browse files
Codegen partial classes. Implements #278
1 parent 841c777 commit 1746ff2

File tree

7 files changed

+53
-14
lines changed

7 files changed

+53
-14
lines changed

src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentDocumentClassifierPass.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ protected override void OnDocumentStructureCreated(
6666
@class.ClassName = computedClass;
6767
@class.Modifiers.Clear();
6868
@class.Modifiers.Add("public");
69+
@class.Modifiers.Add("partial");
6970

7071
method.ReturnType = "void";
7172
method.MethodName = BlazorApi.BlazorComponent.BuildRenderTree;

test/Microsoft.AspNetCore.Blazor.Build.Test/DesignTimeCodeGenerationRazorIntegrationTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace Test
5757
using System.Collections.Generic;
5858
using System.Linq;
5959
using System.Threading.Tasks;
60-
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
60+
public partial class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
6161
{
6262
#pragma warning disable 219
6363
private void __RazorDirectiveTokenHelpers__() {
@@ -142,7 +142,7 @@ namespace Test
142142
using System.Collections.Generic;
143143
using System.Linq;
144144
using System.Threading.Tasks;
145-
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
145+
public partial class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
146146
{
147147
#pragma warning disable 219
148148
private void __RazorDirectiveTokenHelpers__() {
@@ -211,7 +211,7 @@ namespace Test
211211
using System.Collections.Generic;
212212
using System.Linq;
213213
using System.Threading.Tasks;
214-
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
214+
public partial class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
215215
{
216216
#pragma warning disable 219
217217
private void __RazorDirectiveTokenHelpers__() {
@@ -290,7 +290,7 @@ namespace Test
290290
using System.Collections.Generic;
291291
using System.Linq;
292292
using System.Threading.Tasks;
293-
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
293+
public partial class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
294294
{
295295
#pragma warning disable 219
296296
private void __RazorDirectiveTokenHelpers__() {
@@ -385,7 +385,7 @@ namespace Test
385385
386386
#line default
387387
#line hidden
388-
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
388+
public partial class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
389389
{
390390
#pragma warning disable 219
391391
private void __RazorDirectiveTokenHelpers__() {
@@ -468,7 +468,7 @@ namespace Test
468468
using System.Collections.Generic;
469469
using System.Linq;
470470
using System.Threading.Tasks;
471-
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
471+
public partial class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
472472
{
473473
#pragma warning disable 219
474474
private void __RazorDirectiveTokenHelpers__() {

test/Microsoft.AspNetCore.Blazor.Build.Test/RuntimeCodeGenerationRazorIntegrationTest.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace Test
4343
using System.Collections.Generic;
4444
using System.Linq;
4545
using System.Threading.Tasks;
46-
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
46+
public partial class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
4747
{
4848
#pragma warning disable 1998
4949
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
@@ -104,7 +104,7 @@ namespace Test
104104
using System.Collections.Generic;
105105
using System.Linq;
106106
using System.Threading.Tasks;
107-
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
107+
public partial class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
108108
{
109109
#pragma warning disable 1998
110110
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
@@ -158,7 +158,7 @@ namespace Test
158158
using System.Collections.Generic;
159159
using System.Linq;
160160
using System.Threading.Tasks;
161-
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
161+
public partial class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
162162
{
163163
#pragma warning disable 1998
164164
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
@@ -208,7 +208,7 @@ namespace Test
208208
using System.Collections.Generic;
209209
using System.Linq;
210210
using System.Threading.Tasks;
211-
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
211+
public partial class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
212212
{
213213
#pragma warning disable 1998
214214
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
@@ -270,7 +270,7 @@ namespace Test
270270
using System.Collections.Generic;
271271
using System.Linq;
272272
using System.Threading.Tasks;
273-
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
273+
public partial class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
274274
{
275275
#pragma warning disable 1998
276276
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
@@ -338,7 +338,7 @@ namespace Test
338338
using System.Linq;
339339
using System.Threading.Tasks;
340340
using Microsoft.AspNetCore.Blazor;
341-
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
341+
public partial class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
342342
{
343343
#pragma warning disable 1998
344344
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
@@ -398,7 +398,7 @@ namespace Test
398398
using System.Collections.Generic;
399399
using System.Linq;
400400
using System.Threading.Tasks;
401-
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
401+
public partial class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
402402
{
403403
#pragma warning disable 1998
404404
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
@@ -460,7 +460,7 @@ namespace Test
460460
using System.Threading.Tasks;
461461
[Microsoft.AspNetCore.Blazor.Components.RouteAttribute(""/MyPage"")]
462462
[Microsoft.AspNetCore.Blazor.Components.RouteAttribute(""/AnotherRoute/{id}"")]
463-
public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
463+
public partial class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent
464464
{
465465
#pragma warning disable 1998
466466
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)

test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/ComponentRenderingTest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ public void CanTriggerKeyPressEvents()
8181
li => Assert.Equal("b", li.Text));
8282
}
8383

84+
[Fact]
85+
public void CanRenderComponentsWithCodeInOtherPartialClasses()
86+
{
87+
// Initial count is 10
88+
var appElement = MountTestComponent<CounterComponentWithSeparateCodeFile>();
89+
var countDisplayElement = appElement.FindElement(By.TagName("p"));
90+
Assert.Equal("Current count: 10", countDisplayElement.Text);
91+
92+
// Clicking button increments count
93+
appElement.FindElement(By.TagName("button")).Click();
94+
Assert.Equal("Current count: 11", countDisplayElement.Text);
95+
}
96+
8497
[Fact]
8598
public void CanRenderChildComponents()
8699
{
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h1>Counter</h1>
2+
<p>Current count: @currentCount</p>
3+
<button @onclick(IncrementCount)>Click me</button>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace BasicTestApp
5+
{
6+
public partial class CounterComponentWithSeparateCodeFile
7+
{
8+
int currentCount = 0;
9+
10+
// Just to show that we OnInit still works
11+
protected override void OnInit()
12+
{
13+
currentCount = 10;
14+
}
15+
16+
void IncrementCount()
17+
{
18+
currentCount++;
19+
}
20+
}
21+
}

test/testapps/BasicTestApp/wwwroot/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<option value="">Choose...</option>
1313
<option value="BasicTestApp.AddRemoveChildComponents">Add/remove child components</option>
1414
<option value="BasicTestApp.CounterComponent">Counter</option>
15+
<option value="BasicTestApp.CounterComponentWithSeparateCodeFile">Counter with separate code file</option>
1516
<option value="BasicTestApp.CounterComponentUsingChild">Counter using child component</option>
1617
<option value="BasicTestApp.CounterComponentWrapper">Counter wrapped in parent</option>
1718
<option value="BasicTestApp.KeyPressEventComponent">Key press event</option>

0 commit comments

Comments
 (0)