From 5b0368bf7a0cdde0649639a48e28e679828a1e55 Mon Sep 17 00:00:00 2001 From: Aaron Powell Date: Wed, 17 Dec 2025 14:50:05 +1100 Subject: [PATCH 1/2] Changing how null is detected and handled Using the required keyword to indicate what is expected to be passed to the components in the stack. Looking through the usage, only the Values property can come through as null, everything else is set to something that should never be nullable (and then, if it is, it should be considered a proper error to resolve). --- .../UI/Components/TaxonomyInput.razor | 9 +++-- .../Components/TagsInput/TagsInput.razor | 33 ++++++------------- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/LANCommander.Server/UI/Components/TaxonomyInput.razor b/LANCommander.Server/UI/Components/TaxonomyInput.razor index 6214c715..29cee97e 100644 --- a/LANCommander.Server/UI/Components/TaxonomyInput.razor +++ b/LANCommander.Server/UI/Components/TaxonomyInput.razor @@ -8,8 +8,8 @@ OptionLabelSelector="t => t.Name" /> @code { - [Parameter] public BaseDatabaseService DataService { get; set; } - [Parameter] public ICollection Values { get; set; } + [Parameter] public required BaseDatabaseService DataService { get; set; } + [Parameter] public required ICollection? Values { get; set; } [Parameter] public EventCallback> ValuesChanged { get; set; } ICollection _entities = new List(); @@ -21,7 +21,10 @@ async Task Add(string name) { - var taxonomy = Activator.CreateInstance(typeof(TTaxonomy)) as TTaxonomy; + var taxonomy = (TTaxonomy?)Activator.CreateInstance(typeof(TTaxonomy)); + + if (taxonomy == null) + throw new InvalidOperationException($"Could not create instance of type {nameof(TTaxonomy)}"); taxonomy.Name = name; diff --git a/LANCommander.UI/Components/TagsInput/TagsInput.razor b/LANCommander.UI/Components/TagsInput/TagsInput.razor index 5c5044e1..c92d4b9c 100644 --- a/LANCommander.UI/Components/TagsInput/TagsInput.razor +++ b/LANCommander.UI/Components/TagsInput/TagsInput.razor @@ -14,43 +14,30 @@ @code { - [Parameter] public IEnumerable? DataSource { get; set; } = []; - [Parameter] public Func? OptionLabelSelector { get; set; } + [Parameter] public required IEnumerable DataSource { get; set; } + [Parameter] public required Func OptionLabelSelector { get; set; } [Parameter] public Func>? OnCreateTag { get; set; } - [Parameter] public ICollection? Values { get; set; } = []; - [Parameter] public EventCallback?> ValuesChanged { get; set; } + [Parameter] public required ICollection? Values { get; set; } + [Parameter] public EventCallback> ValuesChanged { get; set; } - Dictionary _items = new(); + Dictionary _items = []; IEnumerable _selectedItems = []; bool _loading; bool _locked; - protected override void OnInitialized() - { - GenerateOptions(); - } - - protected override void OnParametersSet() - { - if (Values is null) - Values = []; - } + protected override void OnInitialized() => GenerateOptions(); void GenerateOptions() { - _items = []; + _items.Clear(); - if (OptionLabelSelector != null) - { - if (DataSource != null) - foreach (var item in DataSource.DistinctBy(OptionLabelSelector)) - _items[OptionLabelSelector.Invoke(item)] = item; + foreach (var item in DataSource.DistinctBy(OptionLabelSelector)) + _items[OptionLabelSelector.Invoke(item)] = item; - _selectedItems = Values?.Select(v => OptionLabelSelector.Invoke(v)) ?? []; - } + _selectedItems = Values?.Select(v => OptionLabelSelector.Invoke(v)) ?? []; } async Task OnValuesChanged(IEnumerable values) From eee946c6e02d95539fd275c244163ff5fb589509 Mon Sep 17 00:00:00 2001 From: Aaron Powell Date: Wed, 17 Dec 2025 14:56:26 +1100 Subject: [PATCH 2/2] Updating some missing renames Razor tooling doesn't detect property renames to update usages (known issue tracked in https://github.com/dotnet/razor/issues/7060) --- .../UI/Components/Library/LibraryItemFilter.razor | 12 ++++++------ .../UI/Pages/Depot/Components/DepotFilter.razor | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/LANCommander.Launcher/UI/Components/Library/LibraryItemFilter.razor b/LANCommander.Launcher/UI/Components/Library/LibraryItemFilter.razor index 35650bcc..5225555f 100644 --- a/LANCommander.Launcher/UI/Components/Library/LibraryItemFilter.razor +++ b/LANCommander.Launcher/UI/Components/Library/LibraryItemFilter.razor @@ -41,22 +41,22 @@ - + - + - + - + - + - + diff --git a/LANCommander.Launcher/UI/Pages/Depot/Components/DepotFilter.razor b/LANCommander.Launcher/UI/Pages/Depot/Components/DepotFilter.razor index 68021815..1a522f8b 100644 --- a/LANCommander.Launcher/UI/Pages/Depot/Components/DepotFilter.razor +++ b/LANCommander.Launcher/UI/Pages/Depot/Components/DepotFilter.razor @@ -36,25 +36,25 @@ - + - + - + - + - + - + - +