From 3649eef37b9d018e344cbb5aa147f6c857719b6f Mon Sep 17 00:00:00 2001 From: Chanakya Date: Sun, 25 Aug 2024 14:31:35 +0530 Subject: [PATCH] Fix few more null checks/refs --- Source/Hurl.Library/Models/Ruleset.cs | 2 +- .../ViewModels/StoreRulesetViewModel.cs | 13 ++++++------- Source/Hurl.Settings/Views/RulesetPage.xaml.cs | 6 +++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Source/Hurl.Library/Models/Ruleset.cs b/Source/Hurl.Library/Models/Ruleset.cs index e30588a0..4c6991fa 100644 --- a/Source/Hurl.Library/Models/Ruleset.cs +++ b/Source/Hurl.Library/Models/Ruleset.cs @@ -7,7 +7,7 @@ public class Ruleset [JsonIgnore] public Guid Id { get; set; } = Guid.NewGuid(); - public List Rules { get; set; } + public List Rules { get; set; } = []; public string RulesetName { get; set; } diff --git a/Source/Hurl.Settings/ViewModels/StoreRulesetViewModel.cs b/Source/Hurl.Settings/ViewModels/StoreRulesetViewModel.cs index 53bbebde..9c2fd44a 100644 --- a/Source/Hurl.Settings/ViewModels/StoreRulesetViewModel.cs +++ b/Source/Hurl.Settings/ViewModels/StoreRulesetViewModel.cs @@ -21,7 +21,7 @@ public class StoreRulesetViewModel : ObservableObject public StoreRulesetViewModel() { Id = Guid.NewGuid(); - Browsers = State.Settings.GetBrowsers() + Browsers = State.Settings.Browsers .Select(x => x.Name) .ToList(); Rules = []; @@ -30,7 +30,7 @@ public StoreRulesetViewModel() public StoreRulesetViewModel(Ruleset set) { Id = set.Id; - Browsers = State.Settings.GetBrowsers() + Browsers = State.Settings.Browsers .Select(x => x.Name) .ToList(); Name = set?.RulesetName; @@ -44,9 +44,9 @@ public StoreRulesetViewModel(Ruleset set) if (set?.AltLaunchIndex is int altLaunchIndex) { List altLaunchList = ["< None >"]; - var x = State.Settings.GetBrowsers()[SelectedBrowser] - .AlternateLaunches - .Select(x => x.ItemName) + var x = State.Settings.Browsers[SelectedBrowser] + ?.AlternateLaunches + ?.Select(x => x.ItemName) .ToList(); altLaunchList.AddRange(x); AltLaunches = altLaunchList; @@ -101,8 +101,7 @@ public Ruleset ToRuleSet() { Id = Id, RulesetName = Name ?? "", - // TODO: dont do this, do proper validation - BrowserName = Browsers.ElementAtOrDefault(SelectedBrowser), + BrowserName = Browsers[SelectedBrowser], Rules = Rules.Select(x => x.ToString()).ToList(), AltLaunchIndex = SelectedAltLaunch > 0 ? SelectedAltLaunch - 1 : null }; diff --git a/Source/Hurl.Settings/Views/RulesetPage.xaml.cs b/Source/Hurl.Settings/Views/RulesetPage.xaml.cs index 779ad5ba..76b60baa 100644 --- a/Source/Hurl.Settings/Views/RulesetPage.xaml.cs +++ b/Source/Hurl.Settings/Views/RulesetPage.xaml.cs @@ -133,20 +133,20 @@ private async void ViewRuleset(object sender, RoutedEventArgs e) private void ClickMoveUpRuleset(object sender, RoutedEventArgs e) { - var Id = (Guid)(sender as MenuFlyoutItem).Tag; + var Id = (Guid)(sender as MenuFlyoutItem)!.Tag; ViewModel.MoveRulesetUp(Id); } private void ClickMoveDownRuleset(object sender, RoutedEventArgs e) { - var Id = (Guid)(sender as MenuFlyoutItem).Tag; + var Id = (Guid)(sender as MenuFlyoutItem)!.Tag; ViewModel.MoveRulesetDown(Id); } private void ClickDeleteRuleset(object sender, RoutedEventArgs e) { - var Id = (Guid)(sender as MenuFlyoutItem).Tag; + var Id = (Guid)(sender as MenuFlyoutItem)!.Tag; ViewModel.DeleteRuleset(Id); }