diff --git a/SabreTools.IO/SystemEnvironment.cs b/SabreTools.IO/SystemEnvironment.cs new file mode 100644 index 0000000..ad0e545 --- /dev/null +++ b/SabreTools.IO/SystemEnvironment.cs @@ -0,0 +1,60 @@ +#if NET5_0_OR_GREATER +using System; +#endif +#if NETCOREAPP3_1 +using System.Runtime.InteropServices; +#endif + +namespace SabreTools.IO +{ + /// + /// Helpers for the system environment + /// + public static class SystemEnvironment + { + /// + /// Determine if the current system is MacOS + /// + public static bool IsLinux() + { +#if NETFRAMEWORK + // .NET Framework can never be Linux + return false; +#elif NETCOREAPP3_1 + return RuntimeInformation.IsOSPlatform(OSPlatform.Linux); +#else + return OperatingSystem.IsLinux(); +#endif + } + + /// + /// Determine if the current system is MacOS + /// + public static bool IsMacOS() + { +#if NETFRAMEWORK + // .NET Framework can never be MacOS + return false; +#elif NETCOREAPP3_1 + return RuntimeInformation.IsOSPlatform(OSPlatform.OSX); +#else + return OperatingSystem.IsMacOS(); +#endif + } + + /// + /// Determine if the current system is Windows + /// + public static bool IsWindows() + { +#if NETFRAMEWORK + // .NET Framework is always Windows + return true; +#elif NETCOREAPP3_1 + return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); +#else + return OperatingSystem.IsWindows(); +#endif + } + } +}