Prefer IReadOnlyCollection<> or IReadOnlyList<> over IEnumerable<>
Closes wixtoolset/issues#6422
Rob Mensching committed
Apr 19, 2021 at 16:12 UTC
7f4c41fc2c6ce55f8f1b87a5516573d99a9beec0
30 files changed
+58
-58
src/WixToolset.Core.Burn/Bind/BindBundleCommand.cs
+2
-2
@@ -73,9 +73,9 @@ namespace WixToolset.Core.Burn
73
74
private IVariableResolver VariableResolver { get; }
75
76
- public IEnumerable<IFileTransfer> FileTransfers { get; private set; }
76
+ public IReadOnlyCollection<IFileTransfer> FileTransfers { get; private set; }
77
78
- public IEnumerable<ITrackedFile> TrackedFiles { get; private set; }
78
+ public IReadOnlyCollection<ITrackedFile> TrackedFiles { get; private set; }
79
80
public WixOutput Wixout { get; private set; }
81
src/WixToolset.Core.Burn/ExtensibilityServices/BurnBackendHelper.cs
+1
-1
@@ -46,7 +46,7 @@ namespace WixToolset.Core.Burn.ExtensibilityServices
46
47
public IResolvedDirectory CreateResolvedDirectory(string directoryParent, string name) => this.backendHelper.CreateResolvedDirectory(directoryParent, name);
48
49
- public IEnumerable<ITrackedFile> ExtractEmbeddedFiles(IEnumerable<IExpectedExtractFile> embeddedFiles) => this.backendHelper.ExtractEmbeddedFiles(embeddedFiles);
49
+ public IReadOnlyList<ITrackedFile> ExtractEmbeddedFiles(IEnumerable<IExpectedExtractFile> embeddedFiles) => this.backendHelper.ExtractEmbeddedFiles(embeddedFiles);
50
51
public string GenerateIdentifier(string prefix, params string[] args) => this.backendHelper.GenerateIdentifier(prefix, args);
52
src/WixToolset.Core.ExtensionCache/ExtensionCacheManagerExtensionCommandLine.cs
+1
-1
@@ -21,7 +21,7 @@ namespace WixToolset.Core.ExtensionCache
21
22
private IServiceProvider ServiceProvider { get; }
23
24
- public override IEnumerable<ExtensionCommandLineSwitch> CommandLineSwitches => new ExtensionCommandLineSwitch[]
24
+ public override IReadOnlyCollection<ExtensionCommandLineSwitch> CommandLineSwitches => new ExtensionCommandLineSwitch[]
25
{
26
new ExtensionCommandLineSwitch { Switch = "extension", Description = "Manage extension cache." },
27
};
src/WixToolset.Core.WindowsInstaller/ExtensibilityServices/WindowsInstallerBackendHelper.cs
+1
-1
@@ -37,7 +37,7 @@ namespace WixToolset.Core.WindowsInstaller.ExtensibilityServices
37
38
public IResolvedDirectory CreateResolvedDirectory(string directoryParent, string name) => this.backendHelper.CreateResolvedDirectory(directoryParent, name);
39
40
- public IEnumerable<ITrackedFile> ExtractEmbeddedFiles(IEnumerable<IExpectedExtractFile> embeddedFiles) => this.backendHelper.ExtractEmbeddedFiles(embeddedFiles);
40
+ public IReadOnlyList<ITrackedFile> ExtractEmbeddedFiles(IEnumerable<IExpectedExtractFile> embeddedFiles) => this.backendHelper.ExtractEmbeddedFiles(embeddedFiles);
41
42
public string GenerateIdentifier(string prefix, params string[] args) => this.backendHelper.GenerateIdentifier(prefix, args);
43
src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs
+1
-1
@@ -50,7 +50,7 @@ namespace WixToolset.Core.Bind
50
return extractPath;
51
}
52
53
- public IEnumerable<ExpectedExtractFile> GetExpectedEmbeddedFiles()
53
+ public IReadOnlyList<ExpectedExtractFile> GetExpectedEmbeddedFiles()
54
{
55
var files = new List<ExpectedExtractFile>();
56
src/WixToolset.Core/Bind/ExtractEmbeddedFilesCommand.cs
+1
-1
@@ -17,7 +17,7 @@ namespace WixToolset.Core.Bind
17
this.FilesWithEmbeddedFiles = embeddedFiles;
18
}
19
20
- public IEnumerable<ITrackedFile> TrackedFiles { get; private set; }
20
+ public IReadOnlyList<ITrackedFile> TrackedFiles { get; private set; }
21
22
private IBackendHelper BackendHelper { get; }
23
src/WixToolset.Core/Bind/ResolveFieldsCommand.cs
+1
-1
@@ -36,7 +36,7 @@ namespace WixToolset.Core.Bind
36
37
public bool AllowUnresolvedVariables { private get; set; }
38
39
- public IEnumerable<DelayedField> DelayedFields { get; private set; }
39
+ public IReadOnlyCollection<DelayedField> DelayedFields { get; private set; }
40
41
public void Execute()
42
{
src/WixToolset.Core/BindContext.cs
+7
-7
@@ -18,7 +18,7 @@ namespace WixToolset.Core
18
19
public IServiceProvider ServiceProvider { get; }
20
21
- public IEnumerable<BindPath> BindPaths { get; set; }
21
+ public IReadOnlyCollection<BindPath> BindPaths { get; set; }
22
23
public string BurnStubPath { get; set; }
24
@@ -28,15 +28,15 @@ namespace WixToolset.Core
28
29
public CompressionLevel? DefaultCompressionLevel { get; set; }
30
31
- public IEnumerable<IDelayedField> DelayedFields { get; set; }
31
+ public IReadOnlyCollection<IDelayedField> DelayedFields { get; set; }
32
33
- public IEnumerable<IExpectedExtractFile> ExpectedEmbeddedFiles { get; set; }
33
+ public IReadOnlyCollection<IExpectedExtractFile> ExpectedEmbeddedFiles { get; set; }
34
35
- public IEnumerable<IBinderExtension> Extensions { get; set; }
35
+ public IReadOnlyCollection<IBinderExtension> Extensions { get; set; }
36
37
- public IEnumerable<IFileSystemExtension> FileSystemExtensions { get; set; }
37
+ public IReadOnlyCollection<IFileSystemExtension> FileSystemExtensions { get; set; }
38
39
- public IEnumerable<string> Ices { get; set; }
39
+ public IReadOnlyCollection<string> Ices { get; set; }
40
41
public string IntermediateFolder { get; set; }
42
@@ -54,7 +54,7 @@ namespace WixToolset.Core
54
55
public int? ResolvedLcid { get; set; }
56
57
- public IEnumerable<string> SuppressIces { get; set; }
57
+ public IReadOnlyCollection<string> SuppressIces { get; set; }
58
59
public bool SuppressValidation { get; set; }
60
src/WixToolset.Core/BindResult.cs
+2
-2
@@ -11,9 +11,9 @@ namespace WixToolset.Core
11
{
12
private bool disposed;
13
14
- public IEnumerable<IFileTransfer> FileTransfers { get; set; }
14
+ public IReadOnlyCollection<IFileTransfer> FileTransfers { get; set; }
15
16
- public IEnumerable<ITrackedFile> TrackedFiles { get; set; }
16
+ public IReadOnlyCollection<ITrackedFile> TrackedFiles { get; set; }
17
18
public WixOutput Wixout { get; set; }
19
src/WixToolset.Core/Binder.cs
+1
-1
@@ -58,7 +58,7 @@ namespace WixToolset.Core
58
59
var backendFactories = extensionManager.GetServices<IBackendFactory>();
60
61
- var entrySection = context.IntermediateRepresentation.Sections[0];
61
+ var entrySection = context.IntermediateRepresentation.Sections.First();
62
63
foreach (var factory in backendFactories)
64
{
src/WixToolset.Core/CommandLine/BuildCommand.cs
+5
-5
@@ -216,7 +216,7 @@ namespace WixToolset.Core.CommandLine
216
}
217
}
218
219
- private IEnumerable<Intermediate> CompilePhase(IDictionary<string, string> preprocessorVariables, IEnumerable<SourceFile> sourceFiles, CancellationToken cancellationToken)
219
+ private IReadOnlyList<Intermediate> CompilePhase(IDictionary<string, string> preprocessorVariables, IEnumerable<SourceFile> sourceFiles, CancellationToken cancellationToken)
220
{
221
var intermediates = new List<Intermediate>();
222
@@ -257,7 +257,7 @@ namespace WixToolset.Core.CommandLine
257
return intermediates;
258
}
259
260
- private Intermediate LibraryPhase(IEnumerable<Intermediate> intermediates, IEnumerable<Localization> localizations, bool bindFiles, IEnumerable<IBindPath> bindPaths, CancellationToken cancellationToken)
260
+ private Intermediate LibraryPhase(IReadOnlyCollection<Intermediate> intermediates, IReadOnlyCollection<Localization> localizations, bool bindFiles, IReadOnlyCollection<IBindPath> bindPaths, CancellationToken cancellationToken)
261
{
262
var context = this.ServiceProvider.GetService<ILibraryContext>();
263
context.BindFiles = bindFiles;
@@ -302,7 +302,7 @@ namespace WixToolset.Core.CommandLine
302
return linker.Link(context);
303
}
304
305
- private void BindPhase(Intermediate output, IEnumerable<Localization> localizations, IEnumerable<string> filterCultures, string cabCachePath, IEnumerable<IBindPath> bindPaths, CancellationToken cancellationToken)
305
+ private void BindPhase(Intermediate output, IReadOnlyCollection<Localization> localizations, IReadOnlyCollection<string> filterCultures, string cabCachePath, IReadOnlyCollection<IBindPath> bindPaths, CancellationToken cancellationToken)
306
{
307
var intermediateFolder = this.IntermediateFolder;
308
if (String.IsNullOrEmpty(intermediateFolder))
@@ -405,7 +405,7 @@ namespace WixToolset.Core.CommandLine
405
return Array.Empty<Intermediate>();
406
}
407
408
- private IEnumerable<Localization> LoadLocalizationFiles(IEnumerable<string> locFiles, IDictionary<string, string> preprocessorVariables, CancellationToken cancellationToken)
408
+ private IReadOnlyList<Localization> LoadLocalizationFiles(IEnumerable<string> locFiles, IDictionary<string, string> preprocessorVariables, CancellationToken cancellationToken)
409
{
410
var localizations = new List<Localization>();
411
var parser = this.ServiceProvider.GetService<ILocalizationParser>();
@@ -787,7 +787,7 @@ namespace WixToolset.Core.CommandLine
787
return Data.OutputType.Unknown;
788
}
789
790
- public IEnumerable<string> CalculateFilterCultures()
790
+ public IReadOnlyList<string> CalculateFilterCultures()
791
{
792
var result = new List<string>();
793
src/WixToolset.Core/CommandLine/CompileCommand.cs
+1
-1
@@ -42,7 +42,7 @@ namespace WixToolset.Core.CommandLine
42
43
private Platform Platform { get; }
44
45
- public IEnumerable<string> IncludeSearchPaths { get; }
45
+ public IReadOnlyCollection<string> IncludeSearchPaths { get; }
46
47
public bool ShowLogo => throw new NotImplementedException();
48
src/WixToolset.Core/CompileContext.cs
+1
-1
@@ -21,7 +21,7 @@ namespace WixToolset.Core
21
22
public string CompilationId { get; set; }
23
24
- public IEnumerable<ICompilerExtension> Extensions { get; set; }
24
+ public IReadOnlyCollection<ICompilerExtension> Extensions { get; set; }
25
26
public Platform Platform { get; set; }
27
src/WixToolset.Core/CompilerCore.cs
+1
-1
@@ -1048,7 +1048,7 @@ namespace WixToolset.Core
1048
{
1049
var section = new IntermediateSection(id, type, compilationId);
1050
1051
- this.intermediate.Sections.Add(section);
1051
+ this.intermediate.AddSection(section);
1052
1053
return section;
1054
}
src/WixToolset.Core/DecompileContext.cs
+1
-1
@@ -22,7 +22,7 @@ namespace WixToolset.Core
22
23
public OutputType DecompileType { get; set; }
24
25
- public IEnumerable<IDecompilerExtension> Extensions { get; set; }
25
+ public IReadOnlyCollection<IDecompilerExtension> Extensions { get; set; }
26
27
public string ExtractFolder { get; set; }
28
src/WixToolset.Core/DecompileResult.cs
+1
-1
@@ -11,7 +11,7 @@ namespace WixToolset.Core
11
{
12
public XDocument Document { get; set; }
13
14
- public IEnumerable<string> ExtractedFilePaths { get; set; }
14
+ public IReadOnlyCollection<string> ExtractedFilePaths { get; set; }
15
16
public Platform? Platform { get; set; }
17
}
src/WixToolset.Core/ExtensibilityServices/BackendHelper.cs
+1
-1
@@ -73,7 +73,7 @@ namespace WixToolset.Core.ExtensibilityServices
73
};
74
}
75
76
- public IEnumerable<ITrackedFile> ExtractEmbeddedFiles(IEnumerable<IExpectedExtractFile> embeddedFiles)
76
+ public IReadOnlyList<ITrackedFile> ExtractEmbeddedFiles(IEnumerable<IExpectedExtractFile> embeddedFiles)
77
{
78
var command = new ExtractEmbeddedFilesCommand(this, embeddedFiles);
79
command.Execute();
src/WixToolset.Core/ExtensibilityServices/ExtensionManager.cs
+1
-1
@@ -94,7 +94,7 @@ namespace WixToolset.Core.ExtensibilityServices
94
}
95
}
96
97
- public IEnumerable<T> GetServices<T>() where T : class
97
+ public IReadOnlyCollection<T> GetServices<T>() where T : class
98
{
99
if (!this.loadedExtensionsByType.TryGetValue(typeof(T), out var extensions))
100
{
src/WixToolset.Core/LayoutContext.cs
+4
-4
@@ -17,13 +17,13 @@ namespace WixToolset.Core
17
18
public IServiceProvider ServiceProvider { get; }
19
20
- public IEnumerable<ILayoutExtension> Extensions { get; set; }
20
+ public IReadOnlyCollection<ILayoutExtension> Extensions { get; set; }
21
22
- public IEnumerable<IFileSystemExtension> FileSystemExtensions { get; set; }
22
+ public IReadOnlyCollection<IFileSystemExtension> FileSystemExtensions { get; set; }
23
24
- public IEnumerable<IFileTransfer> FileTransfers { get; set; }
24
+ public IReadOnlyCollection<IFileTransfer> FileTransfers { get; set; }
25
26
- public IEnumerable<ITrackedFile> TrackedFiles { get; set; }
26
+ public IReadOnlyCollection<ITrackedFile> TrackedFiles { get; set; }
27
28
public string IntermediateFolder { get; set; }
29
src/WixToolset.Core/LibraryContext.cs
+4
-4
@@ -23,15 +23,15 @@ namespace WixToolset.Core
23
24
public bool BindFiles { get; set; }
25
26
- public IEnumerable<IBindPath> BindPaths { get; set; }
26
+ public IReadOnlyCollection<IBindPath> BindPaths { get; set; }
27
28
- public IEnumerable<ILibrarianExtension> Extensions { get; set; }
28
+ public IReadOnlyCollection<ILibrarianExtension> Extensions { get; set; }
29
30
public string LibraryId { get; set; }
31
32
- public IEnumerable<Localization> Localizations { get; set; }
32
+ public IReadOnlyCollection<Localization> Localizations { get; set; }
33
34
- public IEnumerable<Intermediate> Intermediates { get; set; }
34
+ public IReadOnlyCollection<Intermediate> Intermediates { get; set; }
35
36
public CancellationToken CancellationToken { get; set; }
37
}
src/WixToolset.Core/LinkContext.cs
+3
-4
@@ -8,7 +8,6 @@ namespace WixToolset.Core
8
using WixToolset.Data;
9
using WixToolset.Extensibility;
10
using WixToolset.Extensibility.Data;
11
- using WixToolset.Extensibility.Services;
11
12
internal class LinkContext : ILinkContext
13
{
@@ -19,13 +18,13 @@ namespace WixToolset.Core
18
19
public IServiceProvider ServiceProvider { get; }
20
22
- public IEnumerable<ILinkerExtension> Extensions { get; set; }
21
+ public IReadOnlyCollection<ILinkerExtension> Extensions { get; set; }
22
24
- public IEnumerable<IExtensionData> ExtensionData { get; set; }
23
+ public IReadOnlyCollection<IExtensionData> ExtensionData { get; set; }
24
25
public OutputType ExpectedOutputType { get; set; }
26
28
- public IEnumerable<Intermediate> Intermediates { get; set; }
27
+ public IReadOnlyCollection<Intermediate> Intermediates { get; set; }
28
29
public ISymbolDefinitionCreator SymbolDefinitionCreator { get; set; }
30
src/WixToolset.Core/PreprocessContext.cs
+2
-2
@@ -18,11 +18,11 @@ namespace WixToolset.Core
18
19
public IServiceProvider ServiceProvider { get; }
20
21
- public IEnumerable<IPreprocessorExtension> Extensions { get; set; }
21
+ public IReadOnlyCollection<IPreprocessorExtension> Extensions { get; set; }
22
23
public Platform Platform { get; set; }
24
25
- public IEnumerable<string> IncludeSearchPaths { get; set; }
25
+ public IReadOnlyCollection<string> IncludeSearchPaths { get; set; }
26
27
public string SourcePath { get; set; }
28
src/WixToolset.Core/PreprocessResult.cs
+1
-1
@@ -10,6 +10,6 @@ namespace WixToolset.Core
10
{
11
public XDocument Document { get; set; }
12
13
- public IEnumerable<IIncludedFile> IncludedFiles { get; set; }
13
+ public IReadOnlyCollection<IIncludedFile> IncludedFiles { get; set; }
14
}
15
}
src/WixToolset.Core/ResolveContext.cs
+5
-5
@@ -19,19 +19,19 @@ namespace WixToolset.Core
19
20
public IServiceProvider ServiceProvider { get; }
21
22
- public IEnumerable<IBindPath> BindPaths { get; set; }
22
+ public IReadOnlyCollection<IBindPath> BindPaths { get; set; }
23
24
- public IEnumerable<IResolverExtension> Extensions { get; set; }
24
+ public IReadOnlyCollection<IResolverExtension> Extensions { get; set; }
25
26
- public IEnumerable<IExtensionData> ExtensionData { get; set; }
26
+ public IReadOnlyCollection<IExtensionData> ExtensionData { get; set; }
27
28
- public IEnumerable<string> FilterCultures { get; set; }
28
+ public IReadOnlyCollection<string> FilterCultures { get; set; }
29
30
public string IntermediateFolder { get; set; }
31
32
public Intermediate IntermediateRepresentation { get; set; }
33
34
- public IEnumerable<Localization> Localizations { get; set; }
34
+ public IReadOnlyCollection<Localization> Localizations { get; set; }
35
36
public IVariableResolver VariableResolver { get; set; }
37
src/WixToolset.Core/ResolveFileResult.cs
+1
-1
@@ -9,6 +9,6 @@ namespace WixToolset.Core
9
{
10
public string Path { get; set; }
11
12
- public IEnumerable<string> CheckedPaths { get; set; }
12
+ public IReadOnlyCollection<string> CheckedPaths { get; set; }
13
}
14
}
src/WixToolset.Core/ResolveResult.cs
+2
-2
@@ -14,9 +14,9 @@ namespace WixToolset.Core
14
15
public int? PackageLcid { get; set; }
16
17
- public IEnumerable<IDelayedField> DelayedFields { get; set; }
17
+ public IReadOnlyCollection<IDelayedField> DelayedFields { get; set; }
18
19
- public IEnumerable<IExpectedExtractFile> ExpectedEmbeddedFiles { get; set; }
19
+ public IReadOnlyCollection<IExpectedExtractFile> ExpectedEmbeddedFiles { get; set; }
20
21
public Intermediate IntermediateRepresentation { get; set; }
22
}
src/WixToolset.Core/Resolver.cs
+1
-1
@@ -77,7 +77,7 @@ namespace WixToolset.Core
77
78
var filesWithEmbeddedFiles = new ExtractEmbeddedFiles();
79
80
- IEnumerable<DelayedField> delayedFields;
80
+ IReadOnlyCollection<DelayedField> delayedFields;
81
{
82
var command = new ResolveFieldsCommand();
83
command.Messaging = this.Messaging;
src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs
+1
-1
@@ -12,7 +12,7 @@ namespace Example.Extension
12
{
13
private string exampleValueFromCommandLine;
14
15
- public IEnumerable<ExtensionCommandLineSwitch> CommandLineSwitches => throw new NotImplementedException();
15
+ public IReadOnlyCollection<ExtensionCommandLineSwitch> CommandLineSwitches => throw new NotImplementedException();
16
17
public ExamplePreprocessorExtensionAndCommandLine()
18
{
src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.cs
+1
-1
@@ -9,7 +9,7 @@ namespace Example.Extension
9
10
internal class ExampleWindowsInstallerBackendExtension : BaseWindowsInstallerBackendBinderExtension
11
{
12
- public override IEnumerable<TableDefinition> TableDefinitions => ExampleTableDefinitions.All;
12
+ public override IReadOnlyCollection<TableDefinition> TableDefinitions => ExampleTableDefinitions.All;
13
14
public override bool TryProcessSymbol(IntermediateSection section, IntermediateSymbol symbol, WindowsInstallerData output, TableDefinitionCollection tableDefinitions)
15
{
src/test/WixToolsetTest.CoreIntegration/LinkerFixture.cs
+3
-2
@@ -3,6 +3,7 @@
3
4
namespace WixToolsetTest.CoreIntegration
5
{
6
+ using System;
7
using System.IO;
8
using System.Linq;
9
using WixBuildTools.TestSupport;
@@ -29,8 +30,8 @@ namespace WixToolsetTest.CoreIntegration
30
31
var creator = serviceProvider.GetService<ISymbolDefinitionCreator>();
32
var context = serviceProvider.GetService<ILinkContext>();
32
- context.Extensions = Enumerable.Empty<WixToolset.Extensibility.ILinkerExtension>();
33
- context.ExtensionData = Enumerable.Empty<WixToolset.Extensibility.IExtensionData>();
33
+ context.Extensions = Array.Empty<WixToolset.Extensibility.ILinkerExtension>();
34
+ context.ExtensionData = Array.Empty<WixToolset.Extensibility.IExtensionData>();
35
context.Intermediates = new[] { intermediate1, intermediate2 };
36
context.SymbolDefinitionCreator = creator;
37