-
Notifications
You must be signed in to change notification settings - Fork 701
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use an interface to make GlobalJsonReader more testable
Add more logging and exception handling Address feedback
Showing
9 changed files
with
389 additions
and
139 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/NuGet.Core/Microsoft.Build.NuGetSdkResolver/FileSystemInfoFullNameEqualityComparer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace Microsoft.Build.NuGetSdkResolver | ||
{ | ||
/// <summary> | ||
/// Represents an implementation of <see cref="IEqualityComparer{T}" /> that compares <see cref="FileSystemInfo" /> objects by the value of their <see cref="FileSystemInfo.FullName" /> property. | ||
/// </summary> | ||
internal sealed class FileSystemInfoFullNameEqualityComparer : IEqualityComparer<FileSystemInfo> | ||
{ | ||
/// <summary> | ||
/// Gets a static singleton for the <see cref="FileSystemInfoFullNameEqualityComparer" /> class. | ||
/// </summary> | ||
public static FileSystemInfoFullNameEqualityComparer Instance = new FileSystemInfoFullNameEqualityComparer(); | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="FileSystemInfoFullNameEqualityComparer" /> class. | ||
/// </summary> | ||
private FileSystemInfoFullNameEqualityComparer() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Determines whether the specified <see cref="FileSystemInfo" /> objects are equal by comparing their <see cref="FileSystemInfo.FullName" /> property. | ||
/// </summary> | ||
/// <param name="x">The first <see cref="FileSystemInfo" /> to compare.</param> | ||
/// <param name="y">The second <see cref="FileSystemInfo" /> to compare.</param> | ||
/// <returns><c>true</c> if the specified <see cref="FileSystemInfo" /> objects' <see cref="FileSystemInfo.FullName" /> property are equal, otherwise <c>false</c>.</returns> | ||
public bool Equals(FileSystemInfo x, FileSystemInfo y) | ||
{ | ||
return string.Equals(x.FullName, y.FullName, StringComparison.Ordinal); | ||
} | ||
|
||
/// <summary> | ||
/// Returns a hash code for the specified <see cref="FileSystemInfo" /> object's <see cref="FileSystemInfo.FullName" /> property. | ||
/// </summary> | ||
/// <param name="obj">The <see cref="FileSystemInfo" /> for which a hash code is to be returned.</param> | ||
/// <returns>A hash code for the specified <see cref="FileSystemInfo" /> object's <see cref="FileSystemInfo.FullName" /> property..</returns> | ||
public int GetHashCode(FileSystemInfo obj) | ||
{ | ||
#if NETFRAMEWORK || NETSTANDARD | ||
return obj.FullName.GetHashCode(); | ||
#else | ||
return obj.FullName.GetHashCode(StringComparison.Ordinal); | ||
#endif | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/NuGet.Core/Microsoft.Build.NuGetSdkResolver/IGlobalJsonReader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.Build.Framework; | ||
|
||
namespace Microsoft.Build.NuGetSdkResolver | ||
{ | ||
/// <summary> | ||
/// Represents an interface for a class that reads global.json. | ||
/// </summary> | ||
internal interface IGlobalJsonReader | ||
{ | ||
/// <summary> | ||
/// Walks up the directory tree to find the first global.json and reads the msbuild-sdks section. | ||
/// </summary> | ||
/// <param name="context">An <see cref="SdkResolverContext" /> to use when locating the file.</param> | ||
/// <param name="fileName">An optional file name to search for, the default is global.json.</param> | ||
/// <returns>A <see cref="Dictionary{String,String}" /> of MSBuild SDK versions from a global.json if found, otherwise <c>null</c>.</returns> | ||
Dictionary<string, string> GetMSBuildSdkVersions(SdkResolverContext context, string fileName = GlobalJsonReader.GlobalJsonFileName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.