From 8c22921b9f064bbaa04ef7e0fac48e266400573f Mon Sep 17 00:00:00 2001 From: StevenTCramer Date: Sun, 15 Aug 2021 13:28:12 +0000 Subject: [PATCH 01/15] clean up a bit using new language features and addressing some analyzer warnings https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1816 --- .../BlazorState/Components/BlazorStateComponent.cs | 11 +++++++---- .../Components/BlazorStateInputComponent.cs | 14 +++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Source/BlazorState/Components/BlazorStateComponent.cs b/Source/BlazorState/Components/BlazorStateComponent.cs index 17230b2e2..4d8b450b5 100644 --- a/Source/BlazorState/Components/BlazorStateComponent.cs +++ b/Source/BlazorState/Components/BlazorStateComponent.cs @@ -10,10 +10,9 @@ namespace BlazorState /// And exposes StateHasChanged /// /// Implements IBlazorStateComponent by Injecting - public class BlazorStateComponent : ComponentBase, IDisposable, - IBlazorStateComponent + public class BlazorStateComponent : ComponentBase, IDisposable, IBlazorStateComponent { - static readonly ConcurrentDictionary s_InstanceCounts = new ConcurrentDictionary(); + static readonly ConcurrentDictionary s_InstanceCounts = new(); public BlazorStateComponent() { @@ -60,6 +59,10 @@ protected T GetState() return Store.GetState(); } - public virtual void Dispose() => Subscriptions.Remove(this); + public virtual void Dispose() + { + Subscriptions.Remove(this); + GC.SuppressFinalize(this); + } } } \ No newline at end of file diff --git a/Source/BlazorState/Components/BlazorStateInputComponent.cs b/Source/BlazorState/Components/BlazorStateInputComponent.cs index b02f14c2e..4841bacdd 100644 --- a/Source/BlazorState/Components/BlazorStateInputComponent.cs +++ b/Source/BlazorState/Components/BlazorStateInputComponent.cs @@ -11,12 +11,12 @@ namespace BlazorState /// And exposes StateHasChanged /// /// Implements IBlazorStateComponent by Injecting - public class BlazorStateInputComponent : InputBase, IDisposable, - IBlazorStateComponent + public class BlazorStateInputComponent : InputBase, IDisposable, IBlazorStateComponent { - protected override bool TryParseValueFromString(string aValue, out TValue aResult, out string aValidationErrorMessage) => TryParseValueFromString(aValue, out aResult, out aValidationErrorMessage); + protected override bool TryParseValueFromString(string aValue, out TValue aResult, out string aValidationErrorMessage) => + TryParseValueFromString(aValue, out aResult, out aValidationErrorMessage); - static readonly ConcurrentDictionary s_InstanceCounts = new ConcurrentDictionary(); + static readonly ConcurrentDictionary s_InstanceCounts = new(); public BlazorStateInputComponent() { @@ -63,6 +63,10 @@ protected T GetState() return Store.GetState(); } - public void Dispose() => Subscriptions.Remove(this); + public void Dispose() + { + Subscriptions.Remove(this); + GC.SuppressFinalize(this); + } } } \ No newline at end of file From ffdf1817ea4f2fbd7bc0837a2780647d4714b049 Mon Sep 17 00:00:00 2001 From: StevenTCramer Date: Sun, 15 Aug 2021 14:04:21 +0000 Subject: [PATCH 02/15] Using Partial classes instead of inheritance in the TestApp Fix the following: BlazorLocation SurveyPrompt ResetButton EventStream MainLayout NavMenu ResetButton SurveyPrompt WeatherForecastsPage --- Tests/TestApp/Client/Components/BlazorLocation.razor | 3 ++- Tests/TestApp/Client/Components/BlazorLocation.razor.cs | 4 ++-- Tests/TestApp/Client/Components/SurveyPrompt.razor | 3 ++- Tests/TestApp/Client/Components/SurveyPrompt.razor.cs | 3 ++- .../Client/Features/Base/Components/ResetButton.razor | 3 ++- .../Client/Features/Base/Components/ResetButton.razor.cs | 2 +- .../Client/Features/EventStream/Components/EventStream.razor | 4 +++- .../Features/EventStream/Components/EventStream.razor.cs | 2 +- Tests/TestApp/Client/Layout/MainLayout.razor | 3 ++- Tests/TestApp/Client/Layout/NavMenu.razor | 4 +++- Tests/TestApp/Client/Layout/NavMenu.razor.cs | 3 +-- Tests/TestApp/Client/Pages/WeatherForecastsPage.razor | 5 +++-- Tests/TestApp/Client/Pages/WeatherForecastsPage.razor.cs | 2 +- 13 files changed, 25 insertions(+), 16 deletions(-) diff --git a/Tests/TestApp/Client/Components/BlazorLocation.razor b/Tests/TestApp/Client/Components/BlazorLocation.razor index 137fc10ff..3a996c2d5 100644 --- a/Tests/TestApp/Client/Components/BlazorLocation.razor +++ b/Tests/TestApp/Client/Components/BlazorLocation.razor @@ -1,3 +1,4 @@ -@inherits BlazorLocationBase +@namespace TestApp.Client.Components +@inherits BaseComponent
@LocationName
diff --git a/Tests/TestApp/Client/Components/BlazorLocation.razor.cs b/Tests/TestApp/Client/Components/BlazorLocation.razor.cs index cd2cbdd16..e48fe41f4 100644 --- a/Tests/TestApp/Client/Components/BlazorLocation.razor.cs +++ b/Tests/TestApp/Client/Components/BlazorLocation.razor.cs @@ -1,10 +1,10 @@ namespace TestApp.Client.Components { - using BlazorState; using BlazorState.Services; using Microsoft.AspNetCore.Components; + using TestApp.Client.Features.Base.Components; - public class BlazorLocationBase : BlazorStateComponent + public partial class BlazorLocation : BaseComponent { [Inject] public BlazorHostingLocation BlazorHostingLocation { get; set; } diff --git a/Tests/TestApp/Client/Components/SurveyPrompt.razor b/Tests/TestApp/Client/Components/SurveyPrompt.razor index 78fe1c7b4..885090c86 100644 --- a/Tests/TestApp/Client/Components/SurveyPrompt.razor +++ b/Tests/TestApp/Client/Components/SurveyPrompt.razor @@ -1,4 +1,5 @@ -@inherits SurveyPromptBase +@namespace TestApp.Client.Components +@inherits BaseComponent