-
Notifications
You must be signed in to change notification settings - Fork 1
Add RegistryExtensions with ContainsSubKey #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
205345b
Add RegistryExtensions with ContainsSubKey extension method
Copilot 083597c
Use SkippableFact to skip registry tests on non-Windows
Copilot 3d89f99
Add Microsoft.Win32.Registry package reference to fix build on netsta…
Copilot b3e66aa
Update PowerKit.Tests/RegistryExtensionsTests.cs
Tyrrrz b9d913e
Merge remote-tracking branch 'origin/prime' into copilot/add-registry…
Copilot 57d9470
Remove Microsoft.Win32.Registry package; exclude RegistryExtensions.c…
Copilot e3538d5
Replace Compile Remove with #if NET5_0_OR_GREATER TFM guard in Regist…
Copilot f318c6c
Merge branch 'prime' of https://github.com/Tyrrrz/PowerKit into copil…
Copilot c41d374
Extend TFM guard to include NETFRAMEWORK in RegistryExtensions.cs
Copilot 2368e1a
Polyfill SupportedOSPlatformAttribute for NETFRAMEWORK consumers
Copilot 86964ec
Remove custom SupportedOSPlatformAttribute polyfill; rely on PolyShim
Copilot 6e0f00d
Update RegistryExtensions.cs
Tyrrrz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,47 @@ | ||
| using System; | ||
| using System.Runtime.Versioning; | ||
| using FluentAssertions; | ||
| using Microsoft.Win32; | ||
| using PowerKit.Extensions; | ||
| using Xunit; | ||
|
|
||
| namespace PowerKit.Tests; | ||
|
|
||
| public class RegistryExtensionsTests | ||
| { | ||
| [SkippableFact] | ||
| [SupportedOSPlatform("windows")] | ||
| public void ContainsSubKey_Exists_Test() | ||
| { | ||
| Skip.IfNot(OperatingSystem.IsWindows()); | ||
|
|
||
| // Arrange | ||
| using var key = Registry.CurrentUser.OpenSubKey("Software", true)!; | ||
| var subKeyName = $"PowerKit.Tests.{Guid.NewGuid():N}"; | ||
|
|
||
| try | ||
| { | ||
| using var subKey = key.CreateSubKey(subKeyName); | ||
|
|
||
| // Act & assert | ||
| key.ContainsSubKey(subKeyName).Should().BeTrue(); | ||
| } | ||
| finally | ||
| { | ||
| key.DeleteSubKeyTree(subKeyName, false); | ||
| } | ||
| } | ||
|
|
||
| [SkippableFact] | ||
| [SupportedOSPlatform("windows")] | ||
| public void ContainsSubKey_NotExists_Test() | ||
| { | ||
| Skip.IfNot(OperatingSystem.IsWindows()); | ||
|
|
||
| // Arrange | ||
| using var key = Registry.CurrentUser.OpenSubKey("Software", false)!; | ||
|
Tyrrrz marked this conversation as resolved.
|
||
|
|
||
| // Act & assert | ||
| key.ContainsSubKey("this-sub-key-definitely-does-not-exist").Should().BeFalse(); | ||
| } | ||
| } | ||
This file contains hidden or 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 @@ | ||
| #if NETFRAMEWORK || NET5_0_OR_GREATER | ||
| using System.Runtime.Versioning; | ||
| using Microsoft.Win32; | ||
|
|
||
| namespace PowerKit.Extensions; | ||
|
|
||
| internal static class RegistryExtensions | ||
| { | ||
| extension(RegistryKey key) | ||
| { | ||
| /// <summary> | ||
| /// Checks whether a sub-key with the specified name exists under the registry key. | ||
| /// </summary> | ||
| [SupportedOSPlatform("windows")] | ||
| public bool ContainsSubKey(string name) | ||
|
Tyrrrz marked this conversation as resolved.
|
||
| { | ||
| using var subKey = key.OpenSubKey(name, false); | ||
|
Tyrrrz marked this conversation as resolved.
|
||
| return subKey is not null; | ||
| } | ||
| } | ||
| } | ||
| #endif | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.