From 9728166b827e8010494fbcb18ab734bb6d523c9b Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Mon, 19 Apr 2021 16:08:25 -0700 Subject: Prefer IReadOnlyCollection<> or IReadOnlyList<> over IEnumerable<> Part of wixtoolset/issues#6422 --- src/WixToolset.Data/Intermediate.cs | 34 ++++++++++++++++++---- .../WindowsInstaller/WindowsInstallerStandard.cs | 4 +-- 2 files changed, 30 insertions(+), 8 deletions(-) (limited to 'src/WixToolset.Data') diff --git a/src/WixToolset.Data/Intermediate.cs b/src/WixToolset.Data/Intermediate.cs index 05ffdbf6..37fe7549 100644 --- a/src/WixToolset.Data/Intermediate.cs +++ b/src/WixToolset.Data/Intermediate.cs @@ -18,6 +18,7 @@ namespace WixToolset.Data private const string WixOutputStreamName = "wix-ir.json"; private readonly Dictionary localizationsByCulture; + private readonly List sections; /// /// Instantiate a new Intermediate. @@ -26,7 +27,7 @@ namespace WixToolset.Data { this.Id = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).TrimEnd('=').Replace('+', '.').Replace('/', '_'); this.localizationsByCulture = new Dictionary(StringComparer.OrdinalIgnoreCase); - this.Sections = new List(); + this.sections = new List(); } public Intermediate(string id, IEnumerable sections, IDictionary localizationsByCulture) : this(id, level: null, sections, localizationsByCulture) @@ -38,7 +39,7 @@ namespace WixToolset.Data this.Id = id; this.Level = level; this.localizationsByCulture = (localizationsByCulture != null) ? new Dictionary(localizationsByCulture, StringComparer.OrdinalIgnoreCase) : new Dictionary(StringComparer.OrdinalIgnoreCase); - this.Sections = (sections != null) ? new List(sections) : new List(); + this.sections = (sections != null) ? new List(sections) : new List(); } /// @@ -54,12 +55,12 @@ namespace WixToolset.Data /// /// Get the localizations contained in this intermediate. /// - public IEnumerable Localizations => this.localizationsByCulture.Values; + public IReadOnlyCollection Localizations => this.localizationsByCulture.Values; /// /// Get the sections contained in this intermediate. /// - public IList Sections { get; } + public IReadOnlyCollection Sections => this.sections; /// /// Loads an intermediate from a path on disk. @@ -146,7 +147,7 @@ namespace WixToolset.Data /// /// Paths to intermediate files saved on disk. /// Returns the loaded intermediates - public static IEnumerable Load(IEnumerable intermediateFiles) + public static IReadOnlyList Load(IEnumerable intermediateFiles) { var creator = new SimpleSymbolDefinitionCreator(); return Intermediate.Load(intermediateFiles, creator); @@ -159,7 +160,7 @@ namespace WixToolset.Data /// ISymbolDefinitionCreator to use when reconstituting the intermediates. /// Suppress checking for wix.dll version mismatches. /// Returns the loaded intermediates - public static IEnumerable Load(IEnumerable intermediateFiles, ISymbolDefinitionCreator creator, bool suppressVersionCheck = false) + public static IReadOnlyList Load(IEnumerable intermediateFiles, ISymbolDefinitionCreator creator, bool suppressVersionCheck = false) { var jsons = new Queue(); var intermediates = new List(); @@ -189,6 +190,27 @@ namespace WixToolset.Data return intermediates; } + /// + /// Adds a section to the intermedaite. + /// + /// Section to add to the intermediate. + /// Section added to the intermediate. + public IntermediateSection AddSection(IntermediateSection section) + { + this.sections.Add(section); + return section; + } + + /// + /// Removes a section from the intermediate. + /// + /// Section to remove. + /// True if the section was removed; otherwise false. + public bool Removesection(IntermediateSection section) + { + return this.sections.Remove(section); + } + /// /// Updates the intermediate level to the specified level. /// diff --git a/src/WixToolset.Data/WindowsInstaller/WindowsInstallerStandard.cs b/src/WixToolset.Data/WindowsInstaller/WindowsInstallerStandard.cs index 0e6092b3..b6930b79 100644 --- a/src/WixToolset.Data/WindowsInstaller/WindowsInstallerStandard.cs +++ b/src/WixToolset.Data/WindowsInstaller/WindowsInstallerStandard.cs @@ -414,12 +414,12 @@ namespace WixToolset.Data.WindowsInstaller /// /// Standard actions. /// - public static IEnumerable StandardActions() => standardActionsById.Values; + public static IReadOnlyCollection StandardActions() => standardActionsById.Values; /// /// Standard directories. /// - public static IEnumerable StandardDirectories() => standardDirectoriesById.Values; + public static IReadOnlyCollection StandardDirectories() => standardDirectoriesById.Values; /// /// Gets the platform specific directory id for a directory. Most directories are not platform -- cgit v1.2.3-55-g6feb