public static string NewLine => "\n";
- private static readonly Lazy<OperatingSystem> s_osVersion = new Lazy<OperatingSystem>(() => GetOperatingSystem(Interop.Sys.GetUnixRelease()));
+ private static OperatingSystem GetOSVersion() => GetOperatingSystem(Interop.Sys.GetUnixRelease());
+ // Tests exercise this method for corner cases via private reflection
private static OperatingSystem GetOperatingSystem(string release)
{
int major = 0, minor = 0, build = 0, revision = 0;
Interop.Kernel32.GetComputerName() ??
throw new InvalidOperationException(SR.InvalidOperation_ComputerName);
- private static readonly unsafe Lazy<OperatingSystem> s_osVersion = new Lazy<OperatingSystem>(() =>
+ private static unsafe OperatingSystem GetOSVersion()
{
var version = new Interop.Kernel32.OSVERSIONINFOEX { dwOSVersionInfoSize = sizeof(Interop.Kernel32.OSVERSIONINFOEX) };
if (!Interop.Kernel32.GetVersionExW(ref version))
PlatformID.Win32NT,
new Version(version.dwMajorVersion, version.dwMinorVersion, version.dwBuildNumber, (version.wServicePackMajor << 16) | version.wServicePackMinor),
Marshal.PtrToStringUni((IntPtr)version.szCSDVersion));
- });
+ }
public static string SystemDirectory
{
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
+using System.Threading;
namespace System
{
public static bool Is64BitOperatingSystem => Is64BitProcess || Is64BitOperatingSystemWhen32BitProcess;
- public static OperatingSystem OSVersion => s_osVersion.Value;
+ private static OperatingSystem s_osVersion;
+
+ public static OperatingSystem OSVersion
+ {
+ get
+ {
+ if (s_osVersion == null)
+ {
+ Interlocked.CompareExchange(ref s_osVersion, GetOSVersion(), null);
+ }
+ return s_osVersion;
+ }
+ }
public static bool UserInteractive => true;