From f6ba876b61adbe7dc5711957a049fb6518aea3ef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 18 Apr 2026 10:21:22 +0000 Subject: [PATCH] Add [SupportedOSPlatformGuard] attributes to OperatingSystem polyfill methods Agent-Logs-Url: https://github.com/Tyrrrz/PolyShim/sessions/5a7623b8-9692-41b7-a49f-61db39e8c7af Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> --- PolyShim/Net50/OperatingSystem.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/PolyShim/Net50/OperatingSystem.cs b/PolyShim/Net50/OperatingSystem.cs index c58fbc26..3aabbc90 100644 --- a/PolyShim/Net50/OperatingSystem.cs +++ b/PolyShim/Net50/OperatingSystem.cs @@ -5,6 +5,7 @@ using System; using System.Runtime.InteropServices; using System.Diagnostics.CodeAnalysis; +using System.Runtime.Versioning; #if !POLYSHIM_INCLUDE_COVERAGE [ExcludeFromCodeCoverage] @@ -16,20 +17,25 @@ internal static class MemberPolyfills_Net50_OperatingSystem // Can only detect the platform on .NET Standard 1.3+ #if !NETSTANDARD || NETSTANDARD1_3_OR_GREATER // https://learn.microsoft.com/dotnet/api/system.operatingsystem.isfreebsd + [SupportedOSPlatformGuard("freebsd")] public static bool IsFreeBSD() => RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD); // https://learn.microsoft.com/dotnet/api/system.operatingsystem.islinux + [SupportedOSPlatformGuard("linux")] public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); // https://learn.microsoft.com/dotnet/api/system.operatingsystem.ismacos + [SupportedOSPlatformGuard("macos")] public static bool IsMacOS() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); // https://learn.microsoft.com/dotnet/api/system.operatingsystem.iswindows + [SupportedOSPlatformGuard("windows")] public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); // Can only detect OS version on .NET Standard 2.0+ and .NET Core 2.0 #if (!NETSTANDARD || NETSTANDARD2_0_OR_GREATER) && (!NETCOREAPP || NETCOREAPP2_0_OR_GREATER) // https://learn.microsoft.com/dotnet/api/system.operatingsystem.iswindowsversionatleast + [SupportedOSPlatformGuard("windows")] public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) { if (!IsWindows())