diff --git a/dotnet/src/webdriver/Firefox/Internal/IniFileReader.cs b/dotnet/src/webdriver/Firefox/Internal/IniFileReader.cs index 656604a4f8635..847af73d567e1 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; } } }