Skip to content

Add [SupportedOSPlatformGuard] to OperatingSystem polyfill methods#123

Merged
Tyrrrz merged 1 commit intoprimefrom
copilot/fix-polyfills-operating-system-checks
Apr 18, 2026
Merged

Add [SupportedOSPlatformGuard] to OperatingSystem polyfill methods#123
Tyrrrz merged 1 commit intoprimefrom
copilot/fix-polyfills-operating-system-checks

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 18, 2026

The polyfilled OperatingSystem.Is*() methods were missing the [SupportedOSPlatformGuard] attributes present on their native .NET 6+ counterparts. Without them, CA1416 doesn't recognize these methods as platform guards on older TFMs, producing spurious warnings for correctly-guarded code:

if (OperatingSystem.IsWindows())
{
    SomeWindowsOnlyApi(); // CA1416 fires here, even though it's guarded
}
  • PolyShim/Net50/OperatingSystem.cs — added [SupportedOSPlatformGuard("…")] to each polyfilled method:
    • IsFreeBSD()"freebsd"
    • IsLinux()"linux"
    • IsMacOS()"macos"
    • IsWindows()"windows"
    • IsWindowsVersionAtLeast(…)"windows"

SupportedOSPlatformGuardAttribute is already polyfilled in PolyShim/Net60/SupportedOSPlatformGuardAttribute.cs, so no new dependency is introduced.

@Tyrrrz Tyrrrz added the bug Something isn't working label Apr 18, 2026
@Tyrrrz Tyrrrz marked this pull request as ready for review April 18, 2026 10:30
Copilot AI review requested due to automatic review settings April 18, 2026 10:30
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.70%. Comparing base (15d4ad5) to head (f6ba876).
⚠️ Report is 1 commits behind head on prime.

Additional details and impacted files
@@            Coverage Diff             @@
##            prime     #123      +/-   ##
==========================================
+ Coverage   90.66%   90.70%   +0.04%     
==========================================
  Files         285      285              
  Lines        4959     4959              
  Branches      404      404              
==========================================
+ Hits         4496     4498       +2     
+ Misses        371      369       -2     
  Partials       92       92              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

This PR updates the OperatingSystem.Is*() polyfills to match the platform-guard annotations present on modern .NET, allowing analyzers (e.g., CA1416) to recognize these methods as valid OS guards on older TFMs.

Changes:

  • Added System.Runtime.Versioning import to the Net50 OperatingSystem polyfill file.
  • Annotated IsFreeBSD(), IsLinux(), IsMacOS(), IsWindows(), and IsWindowsVersionAtLeast(...) with [SupportedOSPlatformGuard("…")].

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

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants