Skip to content

Commit

Permalink
Annotate System.Runtime.InteropServices.RuntimeInformation for nullab…
Browse files Browse the repository at this point in the history
…le reference types (dotnet/corefx#41856)

Commit migrated from dotnet/corefx@fd6714a
  • Loading branch information
stephentoub authored Oct 17, 2019
1 parent c44678c commit c9789de
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum Architecture
public static System.Runtime.InteropServices.OSPlatform OSX { get { throw null; } }
public static System.Runtime.InteropServices.OSPlatform Windows { get { throw null; } }
public static System.Runtime.InteropServices.OSPlatform Create(string osPlatform) { throw null; }
public override bool Equals(object obj) { throw null; }
public override bool Equals(object? obj) { throw null; }
public bool Equals(System.Runtime.InteropServices.OSPlatform other) { throw null; }
public override int GetHashCode() { throw null; }
public static bool operator ==(System.Runtime.InteropServices.OSPlatform left, System.Runtime.InteropServices.OSPlatform right) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Nullable>enable</Nullable>
<Configurations>netcoreapp-Debug;netcoreapp-Release</Configurations>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<RootNamespace>System.Runtime.InteropServices</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<Configurations>netcoreapp-Unix-Debug;netcoreapp-Unix-Release;netcoreapp-Windows_NT-Debug;netcoreapp-Windows_NT-Release</Configurations>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public bool Equals(OSPlatform other)
return Equals(other._osPlatform);
}

internal bool Equals(string other)
internal bool Equals(string? other)
{
return string.Equals(_osPlatform, other, StringComparison.Ordinal);
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return obj is OSPlatform && Equals((OSPlatform)obj);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,18 @@ public static partial class RuntimeInformation
{
private static readonly object s_osLock = new object();
private static readonly object s_processLock = new object();
private static string s_osPlatformName;
private static string s_osDescription;
private static string? s_osPlatformName;
private static string? s_osDescription;
private static Architecture? s_osArch;
private static Architecture? s_processArch;

public static bool IsOSPlatform(OSPlatform osPlatform)
{
string name = s_osPlatformName ?? (s_osPlatformName = Interop.Sys.GetUnixName());
string name = s_osPlatformName ??= Interop.Sys.GetUnixName();
return osPlatform.Equals(name);
}

public static string OSDescription
{
get
{
if (null == s_osDescription)
{
s_osDescription = Interop.Sys.GetUnixVersion();
}

return s_osDescription;
}
}
public static string OSDescription => s_osDescription ??= Interop.Sys.GetUnixVersion();

public static Architecture OSArchitecture
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace System.Runtime.InteropServices
{
public static partial class RuntimeInformation
{
private static string s_osDescription = null;
private static string? s_osDescription = null;
private static readonly object s_osLock = new object();
private static readonly object s_processLock = new object();
private static Architecture? s_osArch = null;
Expand All @@ -19,18 +19,7 @@ public static bool IsOSPlatform(OSPlatform osPlatform)
return OSPlatform.Windows == osPlatform;
}

public static string OSDescription
{
get
{
if (null == s_osDescription)
{
s_osDescription = Interop.NtDll.RtlGetVersion();
}

return s_osDescription;
}
}
public static string OSDescription => s_osDescription ??= Interop.NtDll.RtlGetVersion();

public static Architecture OSArchitecture
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ namespace System.Runtime.InteropServices
public static partial class RuntimeInformation
{
private const string FrameworkName = ".NET Core";
private static string s_frameworkDescription;
private static string? s_frameworkDescription;

public static string FrameworkDescription
{
get
{
if (s_frameworkDescription == null)
{
string versionString = (string)AppContext.GetData("FX_PRODUCT_VERSION");
string? versionString = (string?)AppContext.GetData("FX_PRODUCT_VERSION");

if (versionString == null)
{
Expand Down

0 comments on commit c9789de

Please sign in to comment.