Skip to content

Commit 790d2cf

Browse files
committed
Simplify ToolRestoreResult
There doesn't seem to be a reason to have SaveToCache be a list
1 parent 6fab085 commit 790d2cf

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/Cli/dotnet/Commands/Tool/Restore/ToolPackageRestorer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public ToolPackageRestorer(IToolPackageDownloader toolPackageDownloader,
4747
_fileSystem = fileSystem ?? new FileSystemWrapper();
4848
}
4949

50-
public ToolRestoreResult InstallPackages(
50+
public ToolRestoreResult InstallPackage(
5151
ToolManifestPackage package,
5252
FilePath? configFile)
5353
{
@@ -56,7 +56,7 @@ public ToolRestoreResult InstallPackages(
5656
if (PackageHasBeenRestored(package, targetFramework))
5757
{
5858
return ToolRestoreResult.Success(
59-
saveToCache: [],
59+
saveToCache: null,
6060
message: string.Format(
6161
CliCommandStrings.RestoreSuccessful, package.PackageId,
6262
package.Version.ToNormalizedString(), string.Join(", ", package.CommandNames)));
@@ -89,13 +89,13 @@ public ToolRestoreResult InstallPackages(
8989

9090
return ToolRestoreResult.Success(
9191
saveToCache:
92-
[(new RestoredCommandIdentifier(
92+
(new RestoredCommandIdentifier(
9393
toolPackage.Id,
9494
toolPackage.Version,
9595
NuGetFramework.Parse(targetFramework),
9696
Constants.AnyRid,
9797
toolPackage.Command.Name),
98-
toolPackage.Command)],
98+
toolPackage.Command),
9999
message: string.Format(
100100
CliCommandStrings.RestoreSuccessful,
101101
package.PackageId,

src/Cli/dotnet/Commands/Tool/Restore/ToolRestoreCommand.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,12 @@ public override int Execute()
115115
ToolRestoreResult[] toolRestoreResults =
116116
[.. packagesFromManifest
117117
.AsEnumerable()
118-
.Select(package => toolPackageRestorer.InstallPackages(package, configFile))];
118+
.Select(package => toolPackageRestorer.InstallPackage(package, configFile))];
119119

120120
Dictionary<RestoredCommandIdentifier, ToolCommand> downloaded =
121-
toolRestoreResults.SelectMany(result => result.SaveToCache)
122-
.ToDictionary(pair => pair.Item1, pair => pair.Item2);
121+
toolRestoreResults.Select(result => result.SaveToCache)
122+
.Where(item => item is not null)
123+
.ToDictionary(pair => pair.Value.Item1, pair => pair.Value.Item2);
123124

124125
EnsureNoCommandNameCollision(downloaded);
125126

@@ -202,26 +203,26 @@ private static void EnsureNoCommandNameCollision(Dictionary<RestoredCommandIdent
202203

203204
public struct ToolRestoreResult
204205
{
205-
public (RestoredCommandIdentifier, ToolCommand)[] SaveToCache { get; }
206+
public (RestoredCommandIdentifier, ToolCommand)? SaveToCache { get; }
206207
public bool IsSuccess { get; }
207208
public string Message { get; }
208209

209210
private ToolRestoreResult(
210-
(RestoredCommandIdentifier, ToolCommand)[] saveToCache,
211+
(RestoredCommandIdentifier, ToolCommand)? saveToCache,
211212
bool isSuccess, string message)
212213
{
213214
if (string.IsNullOrWhiteSpace(message))
214215
{
215216
throw new ArgumentException("message", nameof(message));
216217
}
217218

218-
SaveToCache = saveToCache ?? [];
219+
SaveToCache = saveToCache;
219220
IsSuccess = isSuccess;
220221
Message = message;
221222
}
222223

223224
public static ToolRestoreResult Success(
224-
(RestoredCommandIdentifier, ToolCommand)[] saveToCache,
225+
(RestoredCommandIdentifier, ToolCommand)? saveToCache,
225226
string message)
226227
{
227228
return new ToolRestoreResult(saveToCache, true, message);

0 commit comments

Comments
 (0)