Files
mono/netcore/System.Private.CoreLib/shared/System/OperatingSystem.cs
T
Stephen Toub b31b703b89 Turn on nullability for all of Corelib (dotnet/coreclr#24497)
* Enable nullable at the project level

* Remove `#nullable enable` from individual files

Removes `#nullable enable` from almost all .cs files in System.Private.CoreLib. I left it only in the ~30 files (out of ~1480 that had it) that are mirrored to corefx, that are built into projects by corefx that don't yet set NullableContextOptions at the project level, and that use nullable annotations; otherwise, they'd break the corefx build.

Signed-off-by: dotnet-bot <[email protected]>
2019-05-10 10:51:17 +02:00

87 lines
3.1 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
{
#if PROJECTN
[Internal.Runtime.CompilerServices.RelocatedType("System.Runtime.Extensions")]
#endif
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;
}
}
}
}