Skip to content
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

Consider switching from RuntimeInformation.IsOSPlatform(XYZ) to OperatingSystem.IsXYZ() #24653

Closed
adamsitnik opened this issue Aug 7, 2020 · 3 comments
Labels
affected-all This issue impacts all the customers area-blazor Includes: Blazor, Razor Components area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly help wanted Up for grabs. We would accept a PR to help resolve this issue severity-nice-to-have This label is used by an internal tool task
Milestone

Comments

@adamsitnik
Copy link
Member

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

@captainsafia captainsafia added area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly labels Aug 7, 2020
@pranavkm pranavkm added this to the 5.0.0-rc1 milestone Aug 10, 2020
@pranavkm pranavkm added the blocked The work on this issue is blocked due to some dependency label Aug 10, 2020
@ghost
Copy link

ghost commented Aug 10, 2020

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@mkArtakMSFT mkArtakMSFT added task help wanted Up for grabs. We would accept a PR to help resolve this issue and removed blocked The work on this issue is blocked due to some dependency labels Sep 16, 2020
@ghost
Copy link

ghost commented Sep 16, 2020

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@javiercn
Copy link
Member

Seems like this was done.

@ghost ghost locked as resolved and limited conversation to collaborators May 20, 2021
@amcasey amcasey added the area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework label Jun 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-all This issue impacts all the customers area-blazor Includes: Blazor, Razor Components area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly help wanted Up for grabs. We would accept a PR to help resolve this issue severity-nice-to-have This label is used by an internal tool task
Projects
None yet
Development

No branches or pull requests

7 participants