Skip to content

Commit b71c410

Browse files
committed
C#: Re-factor the GetRuntime method.
1 parent 5bc8804 commit b71c410

File tree

1 file changed

+17
-12
lines changed
  • csharp/extractor/Semmle.Extraction.CSharp.Standalone

1 file changed

+17
-12
lines changed

csharp/extractor/Semmle.Extraction.CSharp.Standalone/Runtime.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,33 +140,38 @@ private static IEnumerable<string> DesktopRuntimes
140140
}
141141
}
142142

143-
private IEnumerable<string> GetRuntimes()
143+
/// <summary>
144+
/// Gets the .NET runtime location to use for extraction.
145+
/// </summary>
146+
public string GetRuntime(bool useSelfContained)
144147
{
148+
if (useSelfContained)
149+
{
150+
return ExecutingRuntime;
151+
}
152+
145153
// Gets the newest version of the installed runtimes.
146154
var newestRuntimes = GetNewestRuntimes();
147155

148156
// Location of the newest .NET Core Runtime.
149157
if (newestRuntimes.TryGetValue(netCoreApp, out var netCoreVersion))
150158
{
151-
yield return netCoreVersion.FullPath;
159+
return netCoreVersion.FullPath;
152160
}
153161

154162
// Location of the newest ASP.NET Core Runtime.
155163
if (newestRuntimes.TryGetValue(aspNetCoreApp, out var aspNetCoreVersion))
156164
{
157-
yield return aspNetCoreVersion.FullPath;
165+
return aspNetCoreVersion.FullPath;
158166
}
159167

160-
foreach (var r in DesktopRuntimes)
161-
yield return r;
168+
if (DesktopRuntimes.Any())
169+
{
170+
return DesktopRuntimes.First();
171+
}
162172

163173
// A bad choice if it's the self-contained runtime distributed in codeql dist.
164-
yield return ExecutingRuntime;
174+
return ExecutingRuntime;
165175
}
166-
167-
/// <summary>
168-
/// Gets the .NET runtime location to use for extraction
169-
/// </summary>
170-
public string GetRuntime(bool useSelfContained) => useSelfContained ? ExecutingRuntime : GetRuntimes().First();
171176
}
172-
}
177+
}

0 commit comments

Comments
 (0)