Skip to content

Instantly share code, notes, and snippets.

@sojournercntl
Created December 24, 2019 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sojournercntl/0289533966635ee60df8633723ab56f6 to your computer and use it in GitHub Desktop.
Save sojournercntl/0289533966635ee60df8633723ab56f6 to your computer and use it in GitHub Desktop.
The for OS detection in .net core
public static class OS
{
public static bool IsWin() =>
RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
public static bool IsMac() =>
RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
public static bool IsGnu() =>
RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
public static string GetCurrent()
{
return
(IsWin() ? "win" : null) ??
(IsMac() ? "mac" : null) ??
(IsGnu() ? "gnu" : null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment