Prefer IReadOnlyCollection<> or IReadOnlyList<> over IEnumerable<>
Part of wixtoolset/issues#6422
Rob Mensching committed
Apr 19, 2021 at 16:08 UTC
9728166b827e8010494fbcb18ab734bb6d523c9b
2 files changed
+30
-8
src/WixToolset.Data/Intermediate.cs
+28
-6
@@ -18,6 +18,7 @@ namespace WixToolset.Data
18
private const string WixOutputStreamName = "wix-ir.json";
19
20
private readonly Dictionary<string, Localization> localizationsByCulture;
21
+ private readonly List<IntermediateSection> sections;
22
23
/// <summary>
24
/// Instantiate a new Intermediate.
@@ -26,7 +27,7 @@ namespace WixToolset.Data
27
{
28
this.Id = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).TrimEnd('=').Replace('+', '.').Replace('/', '_');
29
this.localizationsByCulture = new Dictionary<string, Localization>(StringComparer.OrdinalIgnoreCase);
29
- this.Sections = new List<IntermediateSection>();
30
+ this.sections = new List<IntermediateSection>();
31
}
32
33
public Intermediate(string id, IEnumerable<IntermediateSection> sections, IDictionary<string, Localization> localizationsByCulture) : this(id, level: null, sections, localizationsByCulture)
@@ -38,7 +39,7 @@ namespace WixToolset.Data
39
this.Id = id;
40
this.Level = level;
41
this.localizationsByCulture = (localizationsByCulture != null) ? new Dictionary<string, Localization>(localizationsByCulture, StringComparer.OrdinalIgnoreCase) : new Dictionary<string, Localization>(StringComparer.OrdinalIgnoreCase);
41
- this.Sections = (sections != null) ? new List<IntermediateSection>(sections) : new List<IntermediateSection>();
42
+ this.sections = (sections != null) ? new List<IntermediateSection>(sections) : new List<IntermediateSection>();
43
}
44
45
/// <summary>
@@ -54,12 +55,12 @@ namespace WixToolset.Data
55
/// <summary>
56
/// Get the localizations contained in this intermediate.
57
/// </summary>
57
- public IEnumerable<Localization> Localizations => this.localizationsByCulture.Values;
58
+ public IReadOnlyCollection<Localization> Localizations => this.localizationsByCulture.Values;
59
60
/// <summary>
61
/// Get the sections contained in this intermediate.
62
/// </summary>
62
- public IList<IntermediateSection> Sections { get; }
63
+ public IReadOnlyCollection<IntermediateSection> Sections => this.sections;
64
65
/// <summary>
66
/// Loads an intermediate from a path on disk.
@@ -146,7 +147,7 @@ namespace WixToolset.Data
147
/// </summary>
148
/// <param name="intermediateFiles">Paths to intermediate files saved on disk.</param>
149
/// <returns>Returns the loaded intermediates</returns>
149
- public static IEnumerable<Intermediate> Load(IEnumerable<string> intermediateFiles)
150
+ public static IReadOnlyList<Intermediate> Load(IEnumerable<string> intermediateFiles)
151
{
152
var creator = new SimpleSymbolDefinitionCreator();
153
return Intermediate.Load(intermediateFiles, creator);
@@ -159,7 +160,7 @@ namespace WixToolset.Data
160
/// <param name="creator">ISymbolDefinitionCreator to use when reconstituting the intermediates.</param>
161
/// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param>
162
/// <returns>Returns the loaded intermediates</returns>
162
- public static IEnumerable<Intermediate> Load(IEnumerable<string> intermediateFiles, ISymbolDefinitionCreator creator, bool suppressVersionCheck = false)
163
+ public static IReadOnlyList<Intermediate> Load(IEnumerable<string> intermediateFiles, ISymbolDefinitionCreator creator, bool suppressVersionCheck = false)
164
{
165
var jsons = new Queue<JsonWithPath>();
166
var intermediates = new List<Intermediate>();
@@ -189,6 +190,27 @@ namespace WixToolset.Data
190
return intermediates;
191
}
192
193
+ /// <summary>
194
+ /// Adds a section to the intermedaite.
195
+ /// </summary>
196
+ /// <param name="section">Section to add to the intermediate.</param>
197
+ /// <returns>Section added to the intermediate.</returns>
198
+ public IntermediateSection AddSection(IntermediateSection section)
199
+ {
200
+ this.sections.Add(section);
201
+ return section;
202
+ }
203
+
204
+ /// <summary>
205
+ /// Removes a section from the intermediate.
206
+ /// </summary>
207
+ /// <param name="section">Section to remove.</param>
208
+ /// <returns>True if the section was removed; otherwise false.</returns>
209
+ public bool Removesection(IntermediateSection section)
210
+ {
211
+ return this.sections.Remove(section);
212
+ }
213
+
214
/// <summary>
215
/// Updates the intermediate level to the specified level.
216
/// </summary>
src/WixToolset.Data/WindowsInstaller/WindowsInstallerStandard.cs
+2
-2
@@ -414,12 +414,12 @@ namespace WixToolset.Data.WindowsInstaller
414
/// <summary>
415
/// Standard actions.
416
/// </summary>
417
- public static IEnumerable<WixActionSymbol> StandardActions() => standardActionsById.Values;
417
+ public static IReadOnlyCollection<WixActionSymbol> StandardActions() => standardActionsById.Values;
418
419
/// <summary>
420
/// Standard directories.
421
/// </summary>
422
- public static IEnumerable<DirectorySymbol> StandardDirectories() => standardDirectoriesById.Values;
422
+ public static IReadOnlyCollection<DirectorySymbol> StandardDirectories() => standardDirectoriesById.Values;
423
424
/// <summary>
425
/// Gets the platform specific directory id for a directory. Most directories are not platform