From 820fd60321ebad075a0dd27772944d0af6eaa5fd Mon Sep 17 00:00:00 2001 From: nqztv Date: Wed, 26 Jul 2017 23:24:02 -0700 Subject: [PATCH 1/2] Add null-coalescing operator to "Tournament" XAttribute Prevents a runtime error when match.TourneyName is null. If there is no tourney name, use the match description instead. --- SkillKeeper/MainWindow.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SkillKeeper/MainWindow.cs b/SkillKeeper/MainWindow.cs index 9735385..ba7aabd 100644 --- a/SkillKeeper/MainWindow.cs +++ b/SkillKeeper/MainWindow.cs @@ -513,7 +513,7 @@ private void fileSaveButton_Click(object sender, EventArgs e) new XAttribute("ID", match.ID), new XAttribute("Timestamp", match.Timestamp.ToString()), new XAttribute("Order", match.Order), - new XAttribute("Tournament", match.TourneyName), + new XAttribute("Tournament", match.TourneyName ?? match.Description), new XAttribute("Description", match.Description), new XAttribute("Player1", match.Player1), new XAttribute("Player2", match.Player2), From 5956a5b07e86dd645e9d998a7940d18c5223097a Mon Sep 17 00:00:00 2001 From: nqztv Date: Wed, 26 Jul 2017 23:27:41 -0700 Subject: [PATCH 2/2] Reduce right-hand operand of null-coalescing operator Instead of just inserting the whole match description into the tournament attribute if tourneyname is null, just insert the first part of the description. --- SkillKeeper/MainWindow.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SkillKeeper/MainWindow.cs b/SkillKeeper/MainWindow.cs index ba7aabd..467b12d 100644 --- a/SkillKeeper/MainWindow.cs +++ b/SkillKeeper/MainWindow.cs @@ -513,7 +513,7 @@ private void fileSaveButton_Click(object sender, EventArgs e) new XAttribute("ID", match.ID), new XAttribute("Timestamp", match.Timestamp.ToString()), new XAttribute("Order", match.Order), - new XAttribute("Tournament", match.TourneyName ?? match.Description), + new XAttribute("Tournament", match.TourneyName ?? match.Description.Split(new string[] { " - " }, StringSplitOptions.None).First()), new XAttribute("Description", match.Description), new XAttribute("Player1", match.Player1), new XAttribute("Player2", match.Player2), @@ -554,7 +554,7 @@ private void fileUpdateButton_Click(object sender, EventArgs e) new XAttribute("ID", match.ID), new XAttribute("Timestamp", match.Timestamp.ToString()), new XAttribute("Order", match.Order), - new XAttribute("Tournament", match.TourneyName ?? match.Description), + new XAttribute("Tournament", match.TourneyName ?? match.Description.Split(new string[] { " - " }, StringSplitOptions.None).First()), new XAttribute("Description", match.Description), new XAttribute("Player1", match.Player1), new XAttribute("Player2", match.Player2),