-
Notifications
You must be signed in to change notification settings - Fork 694
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get SDK resolver interactivity level from SdkResolverContext (#2390)
* Use reflection via an extension method to get the Interactive property * Improve readability
- Loading branch information
1 parent
d906ebb
commit 62916a4
Showing
2 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/NuGet.Core/Microsoft.Build.NuGetSdkResolver/ExtensionMethods.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,25 @@ | ||
using System.Reflection; | ||
using Microsoft.Build.Framework; | ||
|
||
namespace Microsoft.Build.NuGetSdkResolver | ||
{ | ||
internal static class ExtensionMethods | ||
{ | ||
// In MSBuild 15.9, the SdkResolverContext has an Interactive property. The value will be gotten through reflection so the MSBuild | ||
// references do not need to be updated. | ||
private static readonly PropertyInfo SdkResolverContextInteractivePropertyInfo = typeof(SdkResolverContext).GetRuntimeProperty("Interactive"); | ||
|
||
/// <summary> | ||
/// Determines if the <see cref="SdkResolverContext"/> indicates if there should be no interactivity. | ||
/// </summary> | ||
/// <param name="context">A <see cref="SdkResolverContext"/> instance.</param> | ||
/// <returns><code>true</code> if there should be no interactivity, otherwise <code>false</code>.</returns> | ||
public static bool IsNonInteractive(this SdkResolverContext context) | ||
{ | ||
// Determine if SdkResolverContext's Interactive property, defaulting to false | ||
var interactive = (bool?) SdkResolverContextInteractivePropertyInfo?.GetValue(context) ?? false; | ||
|
||
return !interactive; | ||
} | ||
} | ||
} |
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