-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
affected-allThis issue impacts all the customersThis issue impacts all the customersarea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor Componentsarea-infrastructureIncludes: MSBuild projects/targets, build scripts, CI, Installers and shared frameworkIncludes: MSBuild projects/targets, build scripts, CI, Installers and shared frameworkfeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssemblyThis issue is related to and / or impacts Blazor WebAssemblyhelp wantedUp for grabs. We would accept a PR to help resolve this issueUp for grabs. We would accept a PR to help resolve this issueseverity-nice-to-haveThis label is used by an internal toolThis label is used by an internal tooltask
Milestone
Description
In dotnet/runtime#40457 new methods that allow for instant OS checks were introduced:
namespace System
{
public partial class OperatingSystem
{
// Primary
public static bool IsOSPlatform(string platform);
public static bool IsOSPlatformVersionAtLeast(string platform, int major, int minor = 0, int build = 0, int revision = 0);
// Accelerators for platforms where versions don't make sense
public static bool IsBrowser();
public static bool IsLinux();
// Accelerators with version checks
public static bool IsFreeBSD();
public static bool IsFreeBSDVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0);
public static bool IsAndroid();
public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0);
public static bool IsIOS();
public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0);
public static bool IsMacOS();
public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0);
public static bool IsTvOS();
public static bool IsTvOSVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0);
public static bool IsWatchOS();
public static bool IsWatchOSVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0);
public static bool IsWindows();
public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0);
}
}All the IsXYZ methods (not IsXYZVersionAtLeast()) are basically returning constants and thanks to that, JIT is capable of performing dead code elimination:
if (OperatingSystem.IsWindows())
{
// gets removed as dead code when running on non-windows OSes
}For net5.0 libs/apps you might consider switching from the old API (RuntimeInformation.IsOSPlatform(XYZ)) to the new one.
/cc @davidfowl
Metadata
Metadata
Assignees
Labels
affected-allThis issue impacts all the customersThis issue impacts all the customersarea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor Componentsarea-infrastructureIncludes: MSBuild projects/targets, build scripts, CI, Installers and shared frameworkIncludes: MSBuild projects/targets, build scripts, CI, Installers and shared frameworkfeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssemblyThis issue is related to and / or impacts Blazor WebAssemblyhelp wantedUp for grabs. We would accept a PR to help resolve this issueUp for grabs. We would accept a PR to help resolve this issueseverity-nice-to-haveThis label is used by an internal toolThis label is used by an internal tooltask