mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-26 13:08:24 +01:00
first
This commit is contained in:
parent
bd62d51ec9
commit
b578433e37
1 changed files with 784842 additions and 0 deletions
46
Brutal.Core/Platform.cs
Normal file
46
Brutal.Core/Platform.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
namespace Brutal;
|
||||
|
||||
/// <summary>
|
||||
/// Utility class to determine the current platform
|
||||
/// </summary>
|
||||
public static class Platform
|
||||
{
|
||||
/// <summary> Enum representing supported platform families /// </summary>
|
||||
public enum Family
|
||||
{
|
||||
Windows,
|
||||
Linux,
|
||||
MacOS,
|
||||
}
|
||||
|
||||
/// <summary>The current runtime platform</summary>
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the OperatingSystem instance for the given PlatformFamily
|
||||
/// </summary>
|
||||
public static bool IsUnix(this Platform.Family family)
|
||||
{
|
||||
return family is Platform.Family.Linux or Platform.Family.MacOS;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue