From 660b5a8e49c379e8dedb0f04523a728a2ecde2ee Mon Sep 17 00:00:00 2001 From: Jens True Date: Sun, 1 May 2022 22:29:00 +0200 Subject: [PATCH] Clear out nullable warnings --- Tidstagning/AboutBox.cs | 6 ++++-- Tidstagning/ConfigUI.cs | 4 ---- Tidstagning/MainUI.cs | 24 ++++++++++++++++-------- Tidstagning/Program.cs | 4 +--- Tidstagning/Tidstagning.csproj | 4 ++++ 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/Tidstagning/AboutBox.cs b/Tidstagning/AboutBox.cs index b5faa79..a1e3da3 100644 --- a/Tidstagning/AboutBox.cs +++ b/Tidstagning/AboutBox.cs @@ -40,9 +40,11 @@ namespace Tidstagning { get { - if (Assembly.GetExecutingAssembly().GetName().Version != null) + Version? version = Assembly.GetExecutingAssembly().GetName().Version; + if (version is not null) { - return Assembly.GetExecutingAssembly().GetName().Version.ToString(); + return version.ToString(); + } else { diff --git a/Tidstagning/ConfigUI.cs b/Tidstagning/ConfigUI.cs index fc42f85..d493d94 100644 --- a/Tidstagning/ConfigUI.cs +++ b/Tidstagning/ConfigUI.cs @@ -12,10 +12,6 @@ namespace Tidstagning { public partial class ConfigUI : Form { - - private String OnCommand = ""; - private String OffCommand = ""; - public ConfigUI() { InitializeComponent(); diff --git a/Tidstagning/MainUI.cs b/Tidstagning/MainUI.cs index de9d867..94fa9b2 100644 --- a/Tidstagning/MainUI.cs +++ b/Tidstagning/MainUI.cs @@ -77,7 +77,8 @@ namespace Tidstagning if (e.RowIndex >= 0 && e.ColumnIndex == grid.Columns["DNF"].Index) { entries[e.RowIndex].DNF(); - liste.WriteDNF(entries[e.RowIndex]); + if(liste is not null) + liste.WriteDNF(entries[e.RowIndex]); grid.ClearSelection(); grid.CurrentCell = null; @@ -86,13 +87,15 @@ namespace Tidstagning if (e.RowIndex >= 0 && e.ColumnIndex == grid.Columns["Complete"].Index) { entries[e.RowIndex].Complete(); - liste.WriteComplete(entries[e.RowIndex]); + if(liste is not null) + liste.WriteComplete(entries[e.RowIndex]); grid.ClearSelection(); grid.CurrentCell = null; entries.RemoveAt(e.RowIndex); - horn.Sound((uint)numericSignalLength.Value); + if(horn is not null) + horn.Sound((uint)numericSignalLength.Value); } grid.Refresh(); } @@ -113,7 +116,8 @@ namespace Tidstagning if (checkStartProcedure.Checked) { liste.Write("Automatisk Start Procedure er aktiv."); - startprocedure.setObjects(horn, liste); + if(horn is not null) + startprocedure.setObjects(horn, liste); } else { @@ -126,8 +130,11 @@ namespace Tidstagning { btnStop.Enabled = false; btnStart.Enabled = true; - liste.WriteFooter(); - liste.Close(); + if (liste is not null) + { + liste.WriteFooter(); + liste.Close(); + } checkStartProcedure.Enabled = true; flowLayoutPanelConfiguration.Enabled = true; } @@ -140,7 +147,8 @@ namespace Tidstagning private void btnTest_Click(object sender, EventArgs e) { - horn.Sound((uint)numericSignalLength.Value); + if(horn is not null) + horn.Sound((uint)numericSignalLength.Value); } private void Clock_Tick(object sender, EventArgs e) @@ -154,7 +162,7 @@ namespace Tidstagning private void comboComport_SelectedIndexChanged(object sender, EventArgs e) { - if (comboComport.Items.Count != 0) + if (comboComport is not null && comboComport.Items.Count != 0 && comboComport.SelectedItem is not null) { horn = new Relay(comboComport.SelectedItem.ToString()); Properties.Settings.Default.ComPort = comboComport.SelectedItem.ToString(); diff --git a/Tidstagning/Program.cs b/Tidstagning/Program.cs index 3431f90..2dd5882 100644 --- a/Tidstagning/Program.cs +++ b/Tidstagning/Program.cs @@ -5,9 +5,8 @@ using System.Windows.Forms; namespace Tidstagning { - static class Program + class Program { - public class Options { [Option('c', "config", Required = false, HelpText = "Enable configuration menu.")] @@ -20,7 +19,6 @@ namespace Tidstagning CommandLine.Parser.Default.ParseArguments(args) .WithParsed(RunOptions) .WithNotParsed(HandleParseError); - } static void RunOptions(Options opts) { diff --git a/Tidstagning/Tidstagning.csproj b/Tidstagning/Tidstagning.csproj index d2b19d9..55b9fb8 100644 --- a/Tidstagning/Tidstagning.csproj +++ b/Tidstagning/Tidstagning.csproj @@ -24,6 +24,10 @@ + + + +