System.Environment.OSVersion
在 .net core 5.0 (dnxcore50) 中似乎不是一部分。
我正在尝试确定用户使用的操作系统,以便在将文件保存到文件系统时,我知道是使用 '/' 还是 '\'。
那么我应该使用什么替代方法呢?
你可以把它取回:
using System.Runtime.InteropServices;
namespace System
{
// [ComVisible(true)]
// [Serializable]
public enum PlatformID
{
Win32S = 0,
Win32Windows = 1,
Win32NT = 2,
WinCE = 3,
Unix = 4,
// Since NET 3.5 SP1 or silverlight
Xbox = 5,
MacOSX = 6,
}
public class OperatingSystem
{
private Architecture m_arch;
private bool m_isARM;
private bool m_isX86;
private bool m_isLinux;
private bool m_isOSX;
private bool m_isWindows;
private PlatformID m_platform;
public OperatingSystem()
{
m_arch = RuntimeInformation.ProcessArchitecture;
m_isARM = (m_arch == Architecture.Arm || m_arch == Architecture.Arm64);
m_isX86 = (m_arch == Architecture.X86 || m_arch == Architecture.X64);
m_isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
m_isOSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
m_isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
if (m_isLinux || m_isOSX)
m_platform = PlatformID.Unix;
else if (m_isWindows)
{
m_platform = PlatformID.Win32NT;
}
else
throw new System.PlatformNotSupportedException("Operating system not supported.");
}
public PlatformID Platform
{
get
{
return m_platform;
}
}
}
public class OldEnvironment
{
private static OperatingSystem m_OS;
static OldEnvironment()
{
m_OS = new OperatingSystem();
}
public static OperatingSystem OSVersion
{
get
{
return m_OS;
}
}
}
}
Path.Combine
(除非它也被省略了)。 - Theodoros Chatzigiannakis