Skip to content

Commit 621020b

Browse files
committed
Changes based on code-review.
- All package id and version are compared case-insensitive. - Instead of String use string. - Rename method of INuGetPackageFilter.
1 parent 6696507 commit 621020b

28 files changed

+60
-104
lines changed

src/GitExtensions.PluginManager/PluginSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal class PluginSettings : IEnumerable<ISetting>
2020
/// <summary>
2121
/// Gets current value of <see cref="CloseInstancesProperty"/>.
2222
/// </summary>
23-
public bool CloseInstances => source.GetValue(CloseInstancesProperty.Name, CloseInstancesProperty.DefaultValue, t => Boolean.Parse(t));
23+
public bool CloseInstances => source.GetValue(CloseInstancesProperty.Name, CloseInstancesProperty.DefaultValue, t => bool.Parse(t));
2424

2525
public PluginSettings(ISettingsSource source)
2626
{

src/PackageManager.Cli/Args.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,16 @@ public override string ToString()
105105
{
106106
StringBuilder result = new StringBuilder();
107107

108-
if (!String.IsNullOrEmpty(Path))
108+
if (!string.IsNullOrEmpty(Path))
109109
result.Append($"--path \"{Path}\"");
110110

111-
if (!String.IsNullOrEmpty(SelfPackageId))
111+
if (!string.IsNullOrEmpty(SelfPackageId))
112112
result.Append($" --selfpackageid {SelfPackageId}");
113113

114114
if (IsSelfUpdate)
115115
result.Append(" --selfupdate");
116116

117-
if (!String.IsNullOrEmpty(SelfOriginalPath))
117+
if (!string.IsNullOrEmpty(SelfOriginalPath))
118118
result.Append($" --selforiginalpath \"{SelfOriginalPath}\"");
119119

120120
return result.ToString();

src/PackageManager.Cli/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public async Task MainAsync(string[] args)
4040
UpdatesViewModel viewModel = CreateUpdatesViewModel();
4141
await viewModel.Refresh.ExecuteAsync();
4242

43-
PackageUpdateViewModel packageModel = viewModel.Packages.FirstOrDefault(p => p.Target.Id == Args.PackageId);
43+
PackageUpdateViewModel packageModel = viewModel.Packages.FirstOrDefault(p => string.Equals(p.Target.Id, Args.PackageId, StringComparison.CurrentCultureIgnoreCase));
4444
if (packageModel != null && viewModel.Update.CanExecute(packageModel))
4545
{
4646
await viewModel.Update.ExecuteAsync(packageModel);

src/PackageManager.NuGet/Models/NuGetPackage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task<IPackageContent> GetContentAsync(CancellationToken cancellatio
4949
=> await contentService.DownloadAsync(repository, source, cancellationToken);
5050

5151
public async Task<IEnumerable<IPackage>> GetVersionsAsync(bool isPrereleaseIncluded, CancellationToken cancellationToken)
52-
=> await versionService.GetListAsync(Int32.MaxValue, source, repository, isPrereleaseIncluded: isPrereleaseIncluded, cancellationToken: cancellationToken);
52+
=> await versionService.GetListAsync(int.MaxValue, source, repository, isPrereleaseIncluded: isPrereleaseIncluded, cancellationToken: cancellationToken);
5353

5454
public bool Equals(IPackage other)
5555
=> Equals((IPackageIdentity)other);

src/PackageManager.NuGet/Models/NuGetPackageIdentity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public bool Equals(IPackageIdentity other)
2626
if (other == null)
2727
return false;
2828

29-
return Id == other.Id && Version == other.Version;
29+
return string.Equals(Id, other.Id, StringComparison.CurrentCultureIgnoreCase) && string.Equals(Version, other.Version, StringComparison.CurrentCultureIgnoreCase);
3030
}
3131
}
3232
}

src/PackageManager.NuGet/Models/NuGetPackageSourceCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class NuGetPackageSourceCollection : DisposableBase, IPackageSourceCollec
1717

1818
public event Action Changed;
1919

20-
public IPackageSource Primary => Sources.FirstOrDefault(s => s.Name == Provider.ActivePackageSourceName);
20+
public IPackageSource Primary => Sources.FirstOrDefault(s => string.Equals(s.Name, Provider.ActivePackageSourceName, StringComparison.CurrentCultureIgnoreCase));
2121
public IReadOnlyCollection<IPackageSource> All => Sources;
2222

2323
public NuGetPackageSourceCollection(INuGetPackageSourceProvider provider)
@@ -66,7 +66,7 @@ public void Remove(IPackageSource source)
6666

6767
public void MarkAsPrimary(IPackageSource source)
6868
{
69-
if (Provider.ActivePackageSourceName == source?.Name)
69+
if (string.Equals(Provider.ActivePackageSourceName, source?.Name, StringComparison.CurrentCultureIgnoreCase))
7070
return;
7171

7272
if (source == null)

src/PackageManager.NuGet/Services/EmptyNuGetSearchTermTransformer.cs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,6 @@ public void Transform(NuGetSearchTerm searchTerm)
1313
{
1414
}
1515

16-
#region Singleton
17-
18-
private static EmptyNuGetSearchTermTransformer instance;
19-
private static object instanceLock = new object();
20-
21-
public static EmptyNuGetSearchTermTransformer Instance
22-
{
23-
get
24-
{
25-
if (instance == null)
26-
{
27-
lock (instanceLock)
28-
{
29-
if (instance == null)
30-
instance = new EmptyNuGetSearchTermTransformer();
31-
}
32-
}
33-
34-
return instance;
35-
}
36-
}
37-
38-
#endregion
16+
public readonly static EmptyNuGetSearchTermTransformer Instance = new EmptyNuGetSearchTermTransformer();
3917
}
4018
}

src/PackageManager.NuGet/Services/INuGetPackageFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ namespace PackageManager.Services
1010
{
1111
public interface INuGetPackageFilter
1212
{
13-
Task<NuGetPackageFilterResult> IsPassedAsync(SourceRepository repository, IPackageSearchMetadata package, CancellationToken cancellationToken);
13+
Task<NuGetPackageFilterResult> FilterAsync(SourceRepository repository, IPackageSearchMetadata package, CancellationToken cancellationToken);
1414
}
1515
}

src/PackageManager.NuGet/Services/NuGetInstallService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public bool IsInstalled(string packageId)
6363
using (Stream fileContent = new FileStream(ConfigFilePath, FileMode.Open))
6464
{
6565
PackagesConfigReader reader = new PackagesConfigReader(fileContent);
66-
return reader.GetPackages().Any(p => p.PackageIdentity.Id == packageId);
66+
return reader.GetPackages().Any(p => string.Equals(p.PackageIdentity.Id, packageId, StringComparison.CurrentCultureIgnoreCase));
6767
}
6868
}
6969

@@ -77,7 +77,7 @@ public bool IsInstalled(IPackageIdentity package)
7777
using (Stream fileContent = new FileStream(ConfigFilePath, FileMode.Open))
7878
{
7979
PackagesConfigReader reader = new PackagesConfigReader(fileContent);
80-
return reader.GetPackages().Any(p => p.PackageIdentity.Id == package.Id && p.PackageIdentity.Version.ToFullString() == package.Version);
80+
return reader.GetPackages().Any(p => string.Equals(p.PackageIdentity.Id, package.Id, StringComparison.CurrentCultureIgnoreCase) && string.Equals(p.PackageIdentity.Version.ToFullString(), package.Version, StringComparison.CurrentCultureIgnoreCase));
8181
}
8282
}
8383

@@ -118,7 +118,7 @@ public void Uninstall(string packageId)
118118
ReadPackageConfig(
119119
(p, cache) =>
120120
{
121-
if (p.PackageIdentity.Id == packageId)
121+
if (string.Equals(p.PackageIdentity.Id, packageId, StringComparison.CurrentCultureIgnoreCase))
122122
{
123123
version = p.PackageIdentity.Version;
124124
framework = p.TargetFramework;
@@ -182,7 +182,7 @@ await ReadPackageConfig(
182182
{
183183
log.Debug($"Package '{package.PackageIdentity}' was found.");
184184

185-
NuGetPackageFilterResult filterResult = await packageFilter.IsPassedAsync(repository, metadata, cancellationToken);
185+
NuGetPackageFilterResult filterResult = await packageFilter.FilterAsync(repository, metadata, cancellationToken);
186186
result.Add(new NuGetInstalledPackage(
187187
new NuGetPackage(metadata, repository, contentService, versionService),
188188
filterResult == NuGetPackageFilterResult.Ok
@@ -209,7 +209,7 @@ public async Task<IPackageIdentity> FindInstalledAsync(string packageId, Cancell
209209
await ReadPackageConfig(
210210
(package, context) =>
211211
{
212-
if (package.PackageIdentity.Id == packageId)
212+
if (string.Equals(package.PackageIdentity.Id, packageId, StringComparison.CurrentCultureIgnoreCase))
213213
{
214214
result = new NuGetPackageIdentity(package.PackageIdentity);
215215
return Task.FromResult(true);

src/PackageManager.NuGet/Services/NuGetPackageContentService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public async Task<IPackageContent> DownloadAsync(SourceRepository repository, IP
4141
using (var sourceCacheContext = new SourceCacheContext())
4242
{
4343
var context = new PackageDownloadContext(sourceCacheContext, Path.GetTempPath(), true);
44-
var result = await download.GetDownloadResourceResultAsync(package.Identity, context, String.Empty, nuGetLog, cancellationToken);
44+
var result = await download.GetDownloadResourceResultAsync(package.Identity, context, string.Empty, nuGetLog, cancellationToken);
4545
if (result.Status == DownloadResourceResultStatus.Cancelled)
4646
throw new OperationCanceledException();
4747
else if (result.Status == DownloadResourceResultStatus.NotFound)

0 commit comments

Comments
 (0)