namespace Brutal;
///
/// Utility class to determine the current platform
///
public static class Platform
{
/// Enum representing supported platform families ///
public enum Family
{
Windows,
Linux,
MacOS,
}
/// The current runtime platform
public static readonly Family CurrentFamily;
public static bool IsWindows => CurrentFamily == Family.Windows;
public static bool IsLinux => CurrentFamily == Family.Linux;
public static bool IsMacOS => CurrentFamily == Family.MacOS;
public static bool IsUnix => CurrentFamily.IsUnix();
static Platform()
{
if (OperatingSystem.IsWindows())
CurrentFamily = Family.Windows;
else if (OperatingSystem.IsLinux())
CurrentFamily = Family.Linux;
else if (OperatingSystem.IsMacOS())
CurrentFamily = Family.MacOS;
else
throw new PlatformNotSupportedException("Unsupported platform");
}
}
public static class PlatformFamilyExtensions
{
///
/// Get the OperatingSystem instance for the given PlatformFamily
///
public static bool IsUnix(this Platform.Family family)
{
return family is Platform.Family.Linux or Platform.Family.MacOS;
}
}