Skip to content

Add RegistryExtensions with ContainsSubKey#26

Merged
Tyrrrz merged 12 commits intoprimefrom
copilot/add-registry-extensions
Apr 14, 2026
Merged

Add RegistryExtensions with ContainsSubKey#26
Tyrrrz merged 12 commits intoprimefrom
copilot/add-registry-extensions

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

Ports RegistryExtensions from DotnetRuntimeBootstrapper into PowerKit.

  • RegistryExtensions.ContainsSubKey(string name) — extends RegistryKey; returns true if a sub-key with the given name can be opened. Marked [SupportedOSPlatform("windows")] on all active TFMs to satisfy CA1416. Opens and immediately disposes the sub-key to avoid a resource leak. Guarded with #if NET5_0_OR_GREATER || NETFRAMEWORK so the extension is available on both .NET 5+ and classic .NET Framework; the outer guard also ensures the source file compiles cleanly when PowerKit.csproj targets netstandard2.0 without any extra package reference. SupportedOSPlatformAttribute is polyfilled by PolyShim on non-NET5+ TFMs (including NETFRAMEWORK), so no custom polyfill is needed.
  • RegistryExtensionsTests — two tests (key exists / key does not exist); use [SkippableFact] + Skip.IfNot(OperatingSystem.IsWindows()) so tests are properly reported as skipped on non-Windows CI.
using var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft", false)!;
key.ContainsSubKey("Windows"); // true
key.ContainsSubKey("nonexistent-key"); // false

@Tyrrrz Tyrrrz added the enhancement New feature or request label Apr 14, 2026
@Tyrrrz Tyrrrz marked this pull request as ready for review April 14, 2026 17:14
Copilot AI review requested due to automatic review settings April 14, 2026 17:14
@Tyrrrz
Copy link
Copy Markdown
Owner

Tyrrrz commented Apr 14, 2026

@copilot use SkippableFact to skip tests

@Tyrrrz
Copy link
Copy Markdown
Owner

Tyrrrz commented Apr 14, 2026

@copilot please fix the build

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 14, 2026

@copilot use SkippableFact to skip tests

Done in 083597c. Added xunit.skippablefact 1.5.61 and switched to [SkippableFact] + Skip.IfNot(OperatingSystem.IsWindows()). Tests now show as properly skipped on Linux instead of silently passing.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 14, 2026

@copilot please fix the build

Fixed in 3d89f99. PowerKit targets netstandard2.0 where RegistryKey isn't in the BCL — added Microsoft.Win32.Registry 5.0.0 as a package reference to PowerKit.csproj and Directory.Packages.props. Build now succeeds with 0 errors.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ports a Windows Registry helper into PowerKit by introducing a RegistryKey extension that checks for the presence of a sub-key, along with tests to validate the behavior.

Changes:

  • Add RegistryExtensions.ContainsSubKey(string name) for Microsoft.Win32.RegistryKey.
  • Add xUnit tests covering the “exists” and “does not exist” cases (guarded for Windows).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

File Description
PowerKit/Extensions/RegistryExtensions.cs Adds a RegistryKey extension method to check whether a sub-key can be opened.
PowerKit.Tests/RegistryExtensionsTests.cs Adds tests for the new extension method with a Windows-only runtime guard.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread PowerKit/Extensions/RegistryExtensions.cs
Comment thread PowerKit.Tests/RegistryExtensionsTests.cs
Comment thread PowerKit.Tests/RegistryExtensionsTests.cs Outdated
Comment thread PowerKit.Tests/RegistryExtensionsTests.cs
Comment thread PowerKit/Extensions/RegistryExtensions.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Tyrrrz
Copy link
Copy Markdown
Owner

Tyrrrz commented Apr 14, 2026

@copilot resolve the merge conflicts in this pull request

…-extensions

# Conflicts:
#	Directory.Packages.props
#	PowerKit.Tests/PowerKit.Tests.csproj

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 14, 2026

@copilot resolve the merge conflicts in this pull request

Done in b9d913e. Merged origin/prime — the only conflicts were in Directory.Packages.props and PowerKit.Tests.csproj over the package name casing (xunit.skippablefactXunit.SkippableFact). Resolved by taking the prime casing. All 121 tests pass.

Comment thread PowerKit/PowerKit.csproj Outdated
…s from PowerKit compilation

Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/88654485-94be-46aa-9e01-a8f1ff3ef347

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
…ot/add-registry-extensions

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 14, 2026

@copilot resolve the merge conflicts in this pull request

Done in f318c6c. Merged origin/prime — the only change was adding PrivateAssets="all" to the PolyShim package reference. No conflicts; all 121 tests pass.

Comment thread PowerKit/Extensions/RegistryExtensions.cs Outdated
Comment thread PowerKit/Extensions/RegistryExtensions.cs Outdated
Copilot AI requested a review from Tyrrrz April 14, 2026 18:51
@Tyrrrz
Copy link
Copy Markdown
Owner

Tyrrrz commented Apr 14, 2026

@copilot no, I meant that it should already be polyfilled by PolyShim

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 14, 2026

@copilot no, I meant that it should already be polyfilled by PolyShim

Done in 86964ec. Removed the custom polyfill file — PolyShim's SupportedOSPlatformAttribute.cs already has #if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD), covering NETFRAMEWORK. The [SupportedOSPlatform("windows")] in RegistryExtensions.cs remains unconditional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants