From 91ced6e01e0448e5c5e2197fb4a2504cc5d8356e Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 21 Dec 2024 17:33:29 -0500 Subject: [PATCH 1/3] [dotnet] Add nullability to `IniFileReader` --- .../Firefox/Internal/IniFileReader.cs | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/dotnet/src/webdriver/Firefox/Internal/IniFileReader.cs b/dotnet/src/webdriver/Firefox/Internal/IniFileReader.cs index 656604a4f8635..026d11ee5e14f 100644 --- a/dotnet/src/webdriver/Firefox/Internal/IniFileReader.cs +++ b/dotnet/src/webdriver/Firefox/Internal/IniFileReader.cs @@ -22,19 +22,23 @@ using System.Collections.ObjectModel; using System.IO; +#nullable enable + namespace OpenQA.Selenium.Firefox.Internal { /// /// Parses and reads an INI file. /// - internal class IniFileReader + internal sealed class IniFileReader { - private Dictionary> iniFileStore = new Dictionary>(); + private readonly Dictionary> iniFileStore = new Dictionary>(); /// /// Initializes a new instance of the class. /// /// The full path to the .INI file to be read. + /// If is or . + /// If no file exists at file path . public IniFileReader(string fileName) { if (string.IsNullOrEmpty(fileName)) @@ -53,7 +57,7 @@ public IniFileReader(string fileName) string[] iniFileContent = File.ReadAllLines(fileName); foreach (string iniFileLine in iniFileContent) { - if (!string.IsNullOrEmpty(iniFileLine.Trim()) && !iniFileLine.StartsWith(";", StringComparison.OrdinalIgnoreCase)) + if (!string.IsNullOrWhiteSpace(iniFileLine) && !iniFileLine.StartsWith(";", StringComparison.OrdinalIgnoreCase)) { if (iniFileLine.StartsWith("[", StringComparison.OrdinalIgnoreCase) && iniFileLine.EndsWith("]", StringComparison.OrdinalIgnoreCase)) { @@ -86,14 +90,7 @@ public IniFileReader(string fileName) /// /// Gets a containing the names of the sections in the .INI file. /// - public ReadOnlyCollection SectionNames - { - get - { - List keyList = new List(this.iniFileStore.Keys); - return new ReadOnlyCollection(keyList); - } - } + public ReadOnlyCollection SectionNames => new ReadOnlyCollection(new List(this.iniFileStore.Keys)); /// /// Gets a value from the .INI file. @@ -101,6 +98,16 @@ public ReadOnlyCollection SectionNames /// The section in which to find the key-value pair. /// The key of the key-value pair. /// The value associated with the given section and key. + /// + /// If is or . + /// -or- + /// If is or . + /// + /// + /// If no section named exists + /// -or- + ///If the section does not contain a value named . + /// public string GetValue(string sectionName, string valueName) { if (string.IsNullOrEmpty(sectionName)) @@ -117,19 +124,17 @@ public string GetValue(string sectionName, string valueName) string lowerCaseValueName = valueName.ToUpperInvariant(); - if (!this.iniFileStore.ContainsKey(lowerCaseSectionName)) + if (!this.iniFileStore.TryGetValue(lowerCaseSectionName, out Dictionary? section)) { throw new ArgumentException("Section does not exist: " + sectionName, nameof(sectionName)); } - Dictionary section = this.iniFileStore[lowerCaseSectionName]; - - if (!section.ContainsKey(lowerCaseValueName)) + if (!section.TryGetValue(lowerCaseValueName, out string? value)) { throw new ArgumentException("Value does not exist: " + valueName, nameof(valueName)); } - return section[lowerCaseValueName]; + return value; } } } From db3bac437bb3270beb1fd5c1dcc2e230f0dd4cb1 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 21 Dec 2024 17:41:43 -0500 Subject: [PATCH 2/3] Add period to XML --- dotnet/src/webdriver/Firefox/Internal/IniFileReader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/src/webdriver/Firefox/Internal/IniFileReader.cs b/dotnet/src/webdriver/Firefox/Internal/IniFileReader.cs index 026d11ee5e14f..bcb6889587392 100644 --- a/dotnet/src/webdriver/Firefox/Internal/IniFileReader.cs +++ b/dotnet/src/webdriver/Firefox/Internal/IniFileReader.cs @@ -104,7 +104,7 @@ public IniFileReader(string fileName) /// If is or . /// /// - /// If no section named exists + /// If no section named exists. /// -or- ///If the section does not contain a value named . /// From 4ee76efc10b70c7faa5daac2ff736d6b4de38fbd Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 21 Dec 2024 17:43:40 -0500 Subject: [PATCH 3/3] Fix XMLDoc --- dotnet/src/webdriver/Firefox/Internal/IniFileReader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/src/webdriver/Firefox/Internal/IniFileReader.cs b/dotnet/src/webdriver/Firefox/Internal/IniFileReader.cs index bcb6889587392..847af73d567e1 100644 --- a/dotnet/src/webdriver/Firefox/Internal/IniFileReader.cs +++ b/dotnet/src/webdriver/Firefox/Internal/IniFileReader.cs @@ -101,7 +101,7 @@ public IniFileReader(string fileName) /// /// If is or . /// -or- - /// If is or . + /// If is or . /// /// /// If no section named exists.