diff --git a/SabreTools.Help/Feature.cs b/SabreTools.Help/Feature.cs index 980002ea..c7056faf 100644 --- a/SabreTools.Help/Feature.cs +++ b/SabreTools.Help/Feature.cs @@ -17,10 +17,10 @@ namespace SabreTools.Help #region Publicly facing variables public string? Name { get; protected set; } - public List Flags { get; protected set; } + public readonly List Flags = []; public string? Description { get; protected set; } public string? LongDescription { get; protected set; } - public Dictionary Features { get; protected set; } + public readonly Dictionary Features = []; #endregion @@ -28,35 +28,28 @@ namespace SabreTools.Help public Feature() { + _featureType = ParameterType.Flag; Name = null; - Flags = []; Description = null; LongDescription = null; - _featureType = ParameterType.Flag; - Features = []; } public Feature(string name, string flag, string description, ParameterType featureType, string? longDescription = null) { + _featureType = featureType; Name = name; - Flags = - [ - flag - ]; + Flags.Add(flag); Description = description; LongDescription = longDescription; - _featureType = featureType; - Features = []; } public Feature(string name, List flags, string description, ParameterType featureType, string? longDescription = null) { + _featureType = featureType; Name = name; - Flags = flags; + Flags.AddRange(flags); Description = description; LongDescription = longDescription; - _featureType = featureType; - Features = []; } #endregion @@ -87,7 +80,6 @@ namespace SabreTools.Help /// public void AddFeature(Feature feature) { - Features ??= []; lock (Features) { Features[feature.Name ?? string.Empty] = feature; @@ -100,7 +92,6 @@ namespace SabreTools.Help /// Flag to add for this feature public void AddFlag(string flag) { - Flags ??= []; lock (Flags) { Flags.Add(flag); @@ -113,7 +104,6 @@ namespace SabreTools.Help /// List of flags to add to this feature public void AddFlags(List flags) { - Flags ??= []; lock (Flags) { Flags.AddRange(flags); @@ -281,7 +271,7 @@ namespace SabreTools.Help public List OutputRecursive(int tabLevel, int pre = 0, int midpoint = 0, bool includeLongDescription = false) { // Create the output list - List outputList = new(); + List outputList = []; // Build the output string first string output = string.Empty; diff --git a/SabreTools.Help/FeatureSet.cs b/SabreTools.Help/FeatureSet.cs index 28d37762..d9362131 100644 --- a/SabreTools.Help/FeatureSet.cs +++ b/SabreTools.Help/FeatureSet.cs @@ -8,8 +8,8 @@ namespace SabreTools.Help { #region Private variables - private readonly List _header; - private Dictionary _features; + private readonly List _header = []; + private readonly Dictionary _features = []; private const string _barrier = "-----------------------------------------"; #endregion @@ -18,14 +18,11 @@ namespace SabreTools.Help public FeatureSet() { - _header = []; - _features = []; } public FeatureSet(List header) { - _header = header; - _features = []; + _header.AddRange(header); } #endregion @@ -36,7 +33,6 @@ namespace SabreTools.Help { get { - _features ??= []; if (!_features.ContainsKey(name)) return null; @@ -44,7 +40,6 @@ namespace SabreTools.Help } set { - _features ??= []; _features[name] = value; } } @@ -56,7 +51,6 @@ namespace SabreTools.Help if (subfeature.Name == null) return null; - _features ??= []; if (!_features.ContainsKey(subfeature.Name)) return null; @@ -64,7 +58,6 @@ namespace SabreTools.Help } set { - _features ??= []; if (subfeature.Name != null) _features[subfeature.Name] = value; } @@ -79,7 +72,6 @@ namespace SabreTools.Help if (feature.Name == null) return; - _features ??= []; lock (_features) { _features.Add(feature.Name, feature); diff --git a/SabreTools.Help/TopLevel.cs b/SabreTools.Help/TopLevel.cs index 667e567b..4c291055 100644 --- a/SabreTools.Help/TopLevel.cs +++ b/SabreTools.Help/TopLevel.cs @@ -15,7 +15,7 @@ namespace SabreTools.Help /// /// List of files, directories, and potential wildcard paths /// - public List Inputs = []; + public readonly List Inputs = []; #endregion @@ -50,32 +50,32 @@ namespace SabreTools.Help for (int i = 1; i < args.Length; i++) { // Verify that the current flag is proper for the feature - if (!ValidateInput(args[i])) + if (ValidateInput(args[i])) + continue; + + // Special precautions for files and directories + if (File.Exists(args[i]) || Directory.Exists(args[i])) { - // Special precautions for files and directories - if (File.Exists(args[i]) || Directory.Exists(args[i])) - { - Inputs.Add(args[i]); - } + Inputs.Add(item: args[i]); + } - // Special precautions for wildcarded inputs (potential paths) + // Special precautions for wildcarded inputs (potential paths) #if NETFRAMEWORK - else if (args[i].Contains("*") || args[i].Contains("?")) + else if (args[i].Contains("*") || args[i].Contains("?")) #else - else if (args[i].Contains('*') || args[i].Contains('?')) + else if (args[i].Contains('*') || args[i].Contains('?')) #endif - { - Inputs.Add(args[i]); - } + { + Inputs.Add(args[i]); + } - // Everything else isn't a file - else - { - logger.Error($"Invalid input detected: {args[i]}"); - help.OutputIndividualFeature(Name); - LoggerImpl.Close(); - return false; - } + // Everything else isn't a file + else + { + logger.Error($"Invalid input detected: {args[i]}"); + help.OutputIndividualFeature(Name); + LoggerImpl.Close(); + return false; } }