Skip to content

Commit d0e62a9

Browse files
committed
nfc: Clean up multiple enumerations of IEnumerable<> in WriteSolutionFile().
(This is potentially expensive and the method is public, just a minor code smell.)
1 parent c561b19 commit d0e62a9

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

ICSharpCode.Decompiler/Solution/SolutionCreator.cs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace ICSharpCode.Decompiler.Solution
2929
/// </summary>
3030
public static class SolutionCreator
3131
{
32-
private static readonly XNamespace ProjectFileNamespace = XNamespace.Get("http://schemas.microsoft.com/developer/msbuild/2003");
32+
static readonly XNamespace ProjectFileNamespace = XNamespace.Get("http://schemas.microsoft.com/developer/msbuild/2003");
3333

3434
/// <summary>
3535
/// Writes a solution file to the specified <paramref name="targetFile"/>.
@@ -52,20 +52,22 @@ public static void WriteSolutionFile(string targetFile, IEnumerable<ProjectItem>
5252
throw new ArgumentNullException(nameof(projects));
5353
}
5454

55-
if (!projects.Any())
55+
var projectList = projects.ToList();
56+
57+
if (!projectList.Any())
5658
{
5759
throw new InvalidOperationException("At least one project is expected.");
5860
}
5961

6062
using (var writer = new StreamWriter(targetFile))
6163
{
62-
WriteSolutionFile(writer, projects, targetFile);
64+
WriteSolutionFile(writer, projectList, targetFile);
6365
}
6466

65-
FixProjectReferences(projects);
67+
FixProjectReferences(projectList);
6668
}
6769

68-
private static void WriteSolutionFile(TextWriter writer, IEnumerable<ProjectItem> projects, string solutionFilePath)
70+
static void WriteSolutionFile(TextWriter writer, List<ProjectItem> projects, string solutionFilePath)
6971
{
7072
WriteHeader(writer);
7173
WriteProjects(writer, projects, solutionFilePath);
@@ -90,7 +92,7 @@ private static void WriteHeader(TextWriter writer)
9092
writer.WriteLine("MinimumVisualStudioVersion = 10.0.40219.1");
9193
}
9294

93-
private static void WriteProjects(TextWriter writer, IEnumerable<ProjectItem> projects, string solutionFilePath)
95+
static void WriteProjects(TextWriter writer, List<ProjectItem> projects, string solutionFilePath)
9496
{
9597
foreach (var project in projects)
9698
{
@@ -103,7 +105,7 @@ private static void WriteProjects(TextWriter writer, IEnumerable<ProjectItem> pr
103105
}
104106
}
105107

106-
private static IEnumerable<string> WriteSolutionConfigurations(TextWriter writer, IEnumerable<ProjectItem> projects)
108+
static List<string> WriteSolutionConfigurations(TextWriter writer, List<ProjectItem> projects)
107109
{
108110
var platforms = projects.GroupBy(p => p.PlatformName).Select(g => g.Key).ToList();
109111

@@ -125,10 +127,10 @@ private static IEnumerable<string> WriteSolutionConfigurations(TextWriter writer
125127
return platforms;
126128
}
127129

128-
private static void WriteProjectConfigurations(
130+
static void WriteProjectConfigurations(
129131
TextWriter writer,
130-
IEnumerable<ProjectItem> projects,
131-
IEnumerable<string> solutionPlatforms)
132+
List<ProjectItem> projects,
133+
List<string> solutionPlatforms)
132134
{
133135
writer.WriteLine("\tGlobalSection(ProjectConfigurationPlatforms) = postSolution");
134136

@@ -152,9 +154,11 @@ private static void WriteProjectConfigurations(
152154
writer.WriteLine("\tEndGlobalSection");
153155
}
154156

155-
private static void FixProjectReferences(IEnumerable<ProjectItem> projects)
157+
static void FixProjectReferences(List<ProjectItem> projects)
156158
{
157-
var projectsMap = projects.ToDictionary(p => p.ProjectName, p => p);
159+
var projectsMap = projects.ToDictionary(
160+
p => p.ProjectName,
161+
p => p);
158162

159163
foreach (var project in projects)
160164
{
@@ -192,7 +196,7 @@ private static void FixProjectReferences(string projectFilePath, XElement itemGr
192196
}
193197
}
194198

195-
private static string GetRelativePath(string fromFilePath, string toFilePath)
199+
static string GetRelativePath(string fromFilePath, string toFilePath)
196200
{
197201
Uri fromUri = new Uri(fromFilePath);
198202
Uri toUri = new Uri(toFilePath);

0 commit comments

Comments
 (0)