mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-16 17:10:20 -10:00
Rather than having Environment partially live in corefx and call into an EnvironmentAugments type in CoreLib that in turn calls into an Environment type in CoreLib, we're just moving Environment to live in CoreLib. To start that, this PR moves Environment and its dependencies from their current locations into the shared CoreLib. Those changes will mirror over to coreclr. After that, I'll fix it up to work in CoreLib. And once those changes are built and available back to corefx, I'll update System.Runtime.Extensions to just use the functionality from CoreLib and delete remaining unnecessary code from corefx. Signed-off-by: dotnet-bot <[email protected]>
84 lines
3.0 KiB
C#
84 lines
3.0 KiB
C#
// Licensed to the .NET Foundation under one or more agreements.
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System.Diagnostics;
|
|
using System.Runtime.Serialization;
|
|
|
|
namespace System
|
|
{
|
|
public sealed class OperatingSystem : ISerializable, ICloneable
|
|
{
|
|
private readonly Version _version;
|
|
private readonly PlatformID _platform;
|
|
private readonly string _servicePack;
|
|
private string _versionString;
|
|
|
|
public OperatingSystem(PlatformID platform, Version version) : this(platform, version, null)
|
|
{
|
|
}
|
|
|
|
internal OperatingSystem(PlatformID platform, Version version, string servicePack)
|
|
{
|
|
if (platform < PlatformID.Win32S || platform > PlatformID.MacOSX)
|
|
{
|
|
throw new ArgumentOutOfRangeException(nameof(platform), platform, SR.Format(SR.Arg_EnumIllegalVal, platform));
|
|
}
|
|
|
|
if (version == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(version));
|
|
}
|
|
|
|
_platform = platform;
|
|
_version = version;
|
|
_servicePack = servicePack;
|
|
}
|
|
|
|
public void GetObjectData(SerializationInfo info, StreamingContext context)
|
|
{
|
|
throw new PlatformNotSupportedException();
|
|
}
|
|
|
|
public PlatformID Platform => _platform;
|
|
|
|
public string ServicePack => _servicePack ?? string.Empty;
|
|
|
|
public Version Version => _version;
|
|
|
|
public object Clone() => new OperatingSystem(_platform, _version, _servicePack);
|
|
|
|
public override string ToString() => VersionString;
|
|
|
|
public string VersionString
|
|
{
|
|
get
|
|
{
|
|
if (_versionString == null)
|
|
{
|
|
string os;
|
|
switch (_platform)
|
|
{
|
|
case PlatformID.Win32S: os = "Microsoft Win32S "; break;
|
|
case PlatformID.Win32Windows: os = (_version.Major > 4 || (_version.Major == 4 && _version.Minor > 0)) ? "Microsoft Windows 98 " : "Microsoft Windows 95 "; break;
|
|
case PlatformID.Win32NT: os = "Microsoft Windows NT "; break;
|
|
case PlatformID.WinCE: os = "Microsoft Windows CE "; break;
|
|
case PlatformID.Unix: os = "Unix "; break;
|
|
case PlatformID.Xbox: os = "Xbox "; break;
|
|
case PlatformID.MacOSX: os = "Mac OS X "; break;
|
|
default:
|
|
Debug.Fail($"Unknown platform {_platform}");
|
|
os = "<unknown> "; break;
|
|
}
|
|
|
|
_versionString = string.IsNullOrEmpty(_servicePack) ?
|
|
os + _version.ToString() :
|
|
os + _version.ToString(3) + " " + _servicePack;
|
|
}
|
|
|
|
return _versionString;
|
|
}
|
|
}
|
|
}
|
|
}
|