Skip to content

[API Proposal]: Add missing IsPlatform methods to OperatingSystem class #108632

@HadrienPatte

Description

@HadrienPatte

Background and motivation

The Proposal is the addition of an IsNetBSD, IsIllumos and IsSolaris methods to the OperatingSystem class.

The OperatingSystem class is already able to identify the following platforms through its IsOSPlatform method.

Platform IsPlatform method available
BROWSER ✔️
WASI ✔️
WINDOWS ✔️
OSX ✔️
MACCATALYST ✔️
IOS ✔️
TVOS ✔️
ANDROID ✔️
LINUX ✔️
FREEBSD ✔️
NETBSD
ILLUMOS
SOLARIS

API Proposal

namespace System
{
    public sealed class OperatingSystem : ISerializable, ICloneable
    {
        /// <summary>
        /// Indicates whether the current application is running on NetBSD.
        /// </summary>
        [NonVersionable]
        public static bool IsNetBSD()

        /// <summary>
        /// Indicates whether the current application is running on Illumos.
        /// </summary>
        [NonVersionable]
        public static bool IsIllumos()

        /// <summary>
        /// Indicates whether the current application is running on Solaris.
        /// </summary>
        [NonVersionable]
        public static bool IsSolaris()
    }
}

API Usage

if (OperatingSystem.IsNetBSD())
{
    Console.WriteLine("Running on NetBSD");
}
else if (OperatingSystem.IsIllumos())
{
    Console.WriteLine("Running on Illumos");
}
else if (OperatingSystem.IsSolaris())
{
    Console.WriteLine("Running on Solaris");
}

Alternative Designs

The proposed feature can already be accomplished with OperatingSystem.IsOSPlatform("NETBSD"), OperatingSystem.IsOSPlatform("ILLUMOS") and OperatingSystem.IsOSPlatform("SOLARIS"), but having an IsPlatform method available for each supported platform would make the overall API of the OperatingSystem class more consistent and predictable.

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.Runtimeneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions