using System; using System.Collections.Generic; using System.Text; namespace Apewer { /// 系统实用工具。 public class SystemUtility { #if NETSTD || NETCORE /// 当前操作系统是 Windows。 public static bool IsWindows { get => System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows); } /// 当前操作系统是 OS X 或 macOS。 public static bool IsOSX { get => System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX); } /// 当前操作系统是 Linux。 public static bool IsLinux { get => System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux); } #endif /// public static void SetConsoleCtrlCancel(Func exit) { const string postfix = " - 按 CTRL + C 可安全退出"; var title = Console.Title; if (!title.EndsWith(postfix)) { title = title + postfix; Console.Title = title; } if (exit == null) return; Console.CancelKeyPress += (s, e) => { e.Cancel = !exit(); }; } } }