Skip to content

Commit

Permalink
Switch from Tuple to ValueTuple for Dictionary keys (#5554)
Browse files Browse the repository at this point in the history
  • Loading branch information
Erarndt authored Jan 8, 2024
1 parent ac17919 commit 2f6aaee
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/NuGet.Core/NuGet.Commands/RestoreCommand/LockFileBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public LockFile CreateLockFile(LockFile previousLockFile,
Version = _lockFileVersion
};

var previousLibraries = previousLockFile?.Libraries.ToDictionary(l => Tuple.Create(l.Name, l.Version));
var previousLibraries = previousLockFile?.Libraries.ToDictionary(l => ValueTuple.Create(l.Name, l.Version));

if (project.RestoreMetadata?.ProjectStyle == ProjectStyle.PackageReference ||
project.RestoreMetadata?.ProjectStyle == ProjectStyle.DotnetToolReference)
Expand Down Expand Up @@ -139,7 +139,7 @@ public LockFile CreateLockFile(LockFile previousLockFile,
LockFileLibrary lockFileLib = null;
LockFileLibrary previousLibrary = null;

if (previousLibraries?.TryGetValue(Tuple.Create(package.Id, package.Version), out previousLibrary) == true)
if (previousLibraries?.TryGetValue(ValueTuple.Create(package.Id, package.Version), out previousLibrary) == true)
{
// Check that the previous library is still valid
if (previousLibrary != null
Expand All @@ -165,7 +165,7 @@ public LockFile CreateLockFile(LockFile previousLockFile,
}
}

Dictionary<Tuple<string, NuGetVersion>, LockFileLibrary> libraries = EnsureUniqueLockFileLibraries(lockFile);
Dictionary<ValueTuple<string, NuGetVersion>, LockFileLibrary> libraries = EnsureUniqueLockFileLibraries(lockFile);

var librariesWithWarnings = new HashSet<LibraryIdentity>();

Expand Down Expand Up @@ -233,7 +233,7 @@ public LockFile CreateLockFile(LockFile previousLockFile,

(LockFileTargetLibrary targetLibrary, bool usedFallbackFramework) = LockFileUtils.CreateLockFileTargetLibrary(
libraryDependency?.Aliases,
libraries[Tuple.Create(library.Name, library.Version)],
libraries[ValueTuple.Create(library.Name, library.Version)],
package,
targetGraph,
dependencyType: includeFlags,
Expand All @@ -253,7 +253,7 @@ public LockFile CreateLockFile(LockFile previousLockFile,

var targetLibraryWithoutFallback = LockFileUtils.CreateLockFileTargetLibrary(
libraryDependency?.Aliases,
libraries[Tuple.Create(library.Name, library.Version)],
libraries[ValueTuple.Create(library.Name, library.Version)],
package,
targetGraph,
targetFrameworkOverride: nonFallbackFramework,
Expand Down Expand Up @@ -302,14 +302,14 @@ public LockFile CreateLockFile(LockFile previousLockFile,
return lockFile;
}

private Dictionary<Tuple<string, NuGetVersion>, LockFileLibrary> EnsureUniqueLockFileLibraries(LockFile lockFile)
private Dictionary<ValueTuple<string, NuGetVersion>, LockFileLibrary> EnsureUniqueLockFileLibraries(LockFile lockFile)
{
IList<LockFileLibrary> libraries = lockFile.Libraries;
var libraryReferences = new Dictionary<Tuple<string, NuGetVersion>, LockFileLibrary>();
var libraryReferences = new Dictionary<ValueTuple<string, NuGetVersion>, LockFileLibrary>();

foreach (LockFileLibrary lib in libraries)
{
var libraryKey = Tuple.Create(lib.Name, lib.Version);
var libraryKey = ValueTuple.Create(lib.Name, lib.Version);

if (libraryReferences.TryGetValue(libraryKey, out LockFileLibrary existingLibrary))
{
Expand All @@ -328,7 +328,7 @@ private Dictionary<Tuple<string, NuGetVersion>, LockFileLibrary> EnsureUniqueLoc
if (lockFile.Libraries.Count != libraryReferences.Count)
{
lockFile.Libraries = new List<LockFileLibrary>(libraryReferences.Count);
foreach (KeyValuePair<Tuple<string, NuGetVersion>, LockFileLibrary> pair in libraryReferences)
foreach (KeyValuePair<ValueTuple<string, NuGetVersion>, LockFileLibrary> pair in libraryReferences)
{
lockFile.Libraries.Add(pair.Value);
}
Expand Down

0 comments on commit 2f6aaee

Please sign in to comment.