diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/System.Runtime.InteropServices.RuntimeInformation.sln b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/System.Runtime.InteropServices.RuntimeInformation.sln index b10ca0b23bc11e..f15a24c36f07c9 100644 --- a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/System.Runtime.InteropServices.RuntimeInformation.sln +++ b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/System.Runtime.InteropServices.RuntimeInformation.sln @@ -10,6 +10,8 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + FreeBSD_Debug|Any CPU = FreeBSD_Debug|Any CPU + FreeBSD_Release|Any CPU = FreeBSD_Release|Any CPU Linux_Debug|Any CPU = Linux_Debug|Any CPU Linux_Release|Any CPU = Linux_Release|Any CPU OSX_Debug|Any CPU = OSX_Debug|Any CPU @@ -19,8 +21,10 @@ Global Windows_Release|Any CPU = Windows_Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {F9DF2357-81B4-4317-908E-512DA9395583}.Debug|Any CPU.ActiveCfg = Windows_Debug|Any CPU - {F9DF2357-81B4-4317-908E-512DA9395583}.Debug|Any CPU.Build.0 = Windows_Debug|Any CPU + {F9DF2357-81B4-4317-908E-512DA9395583}.FreeBSD_Debug|Any CPU.ActiveCfg = FreeBSD_Debug|Any CPU + {F9DF2357-81B4-4317-908E-512DA9395583}.FreeBSD_Debug|Any CPU.Build.0 = FreeBSD_Debug|Any CPU + {F9DF2357-81B4-4317-908E-512DA9395583}.FreeBSD_Release|Any CPU.ActiveCfg = FreeBSD_Release|Any CPU + {F9DF2357-81B4-4317-908E-512DA9395583}.FreeBSD_Release|Any CPU.Build.0 = FreeBSD_Release|Any CPU {F9DF2357-81B4-4317-908E-512DA9395583}.Linux_Debug|Any CPU.ActiveCfg = Linux_Debug|Any CPU {F9DF2357-81B4-4317-908E-512DA9395583}.Linux_Debug|Any CPU.Build.0 = Linux_Debug|Any CPU {F9DF2357-81B4-4317-908E-512DA9395583}.Linux_Release|Any CPU.ActiveCfg = Linux_Release|Any CPU @@ -29,14 +33,14 @@ Global {F9DF2357-81B4-4317-908E-512DA9395583}.OSX_Debug|Any CPU.Build.0 = OSX_Debug|Any CPU {F9DF2357-81B4-4317-908E-512DA9395583}.OSX_Release|Any CPU.ActiveCfg = OSX_Release|Any CPU {F9DF2357-81B4-4317-908E-512DA9395583}.OSX_Release|Any CPU.Build.0 = OSX_Release|Any CPU - {F9DF2357-81B4-4317-908E-512DA9395583}.Release|Any CPU.ActiveCfg = Windows_Release|Any CPU - {F9DF2357-81B4-4317-908E-512DA9395583}.Release|Any CPU.Build.0 = Windows_Release|Any CPU {F9DF2357-81B4-4317-908E-512DA9395583}.Windows_Debug|Any CPU.ActiveCfg = Windows_Debug|Any CPU {F9DF2357-81B4-4317-908E-512DA9395583}.Windows_Debug|Any CPU.Build.0 = Windows_Debug|Any CPU {F9DF2357-81B4-4317-908E-512DA9395583}.Windows_Release|Any CPU.ActiveCfg = Windows_Release|Any CPU {F9DF2357-81B4-4317-908E-512DA9395583}.Windows_Release|Any CPU.Build.0 = Windows_Release|Any CPU - {9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.FreeBSD_Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.FreeBSD_Debug|Any CPU.Build.0 = Debug|Any CPU + {9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.FreeBSD_Release|Any CPU.ActiveCfg = Release|Any CPU + {9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.FreeBSD_Release|Any CPU.Build.0 = Release|Any CPU {9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Linux_Debug|Any CPU.ActiveCfg = Debug|Any CPU {9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Linux_Debug|Any CPU.Build.0 = Debug|Any CPU {9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Linux_Release|Any CPU.ActiveCfg = Release|Any CPU @@ -45,8 +49,6 @@ Global {9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.OSX_Debug|Any CPU.Build.0 = Debug|Any CPU {9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.OSX_Release|Any CPU.ActiveCfg = Release|Any CPU {9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.OSX_Release|Any CPU.Build.0 = Release|Any CPU - {9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Release|Any CPU.Build.0 = Release|Any CPU {9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Windows_Debug|Any CPU.ActiveCfg = Debug|Any CPU {9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Windows_Debug|Any CPU.Build.0 = Debug|Any CPU {9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Windows_Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/OSPlatform.cs b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/OSPlatform.cs index 34a425499f742d..d952f5cef3be73 100644 --- a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/OSPlatform.cs +++ b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/OSPlatform.cs @@ -7,35 +7,37 @@ public struct OSPlatform : IEquatable { private readonly string _osPlatform; - private const string WindowsName = "WINDOWS"; + private const string FreeBSDName = "FREEBSD"; private const string LinuxName = "LINUX"; private const string OSXName = "OSX"; + private const string WindowsName = "WINDOWS"; - private static readonly OSPlatform s_windows = new OSPlatform(WindowsName); + private static readonly OSPlatform s_freebsd = new OSPlatform(FreeBSDName); private static readonly OSPlatform s_linux = new OSPlatform(LinuxName); private static readonly OSPlatform s_osx = new OSPlatform(OSXName); + private static readonly OSPlatform s_windows = new OSPlatform(WindowsName); - public static OSPlatform Windows + public static OSPlatform Linux { get { - return s_windows; + return s_linux; } } - public static OSPlatform Linux + public static OSPlatform OSX { get { - return s_linux; + return s_osx; } } - public static OSPlatform OSX + public static OSPlatform Windows { get { - return s_osx; + return s_windows; } } diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/RuntimeInformation.FreeBSD.cs b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/RuntimeInformation.FreeBSD.cs new file mode 100644 index 00000000000000..73b13fec4ccd55 --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/RuntimeInformation.FreeBSD.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace System.Runtime.InteropServices +{ + public static class RuntimeInformation + { + private static OSPlatform s_freeBSD = OSPlatform.Create("FREEBSD"); + + public static bool IsOSPlatform(OSPlatform osPlatform) + { + return s_freeBSD == osPlatform; + } + } +} diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System.Runtime.InteropServices.RuntimeInformation.csproj b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System.Runtime.InteropServices.RuntimeInformation.csproj index 8c1f6e7145992e..492d9f37aebd71 100644 --- a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System.Runtime.InteropServices.RuntimeInformation.csproj +++ b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System.Runtime.InteropServices.RuntimeInformation.csproj @@ -11,14 +11,16 @@ {F9DF2357-81B4-4317-908E-512DA9395583} + + - - + + @@ -26,6 +28,9 @@ + + + diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs index 2303945c2ffe6d..1925c0e3a7d6e8 100644 --- a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs +++ b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs @@ -1,26 +1,17 @@ -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; using Xunit; namespace System.Runtime.InteropServices.RuntimeInformationTests { public class CheckPlatformTests { - [Fact, PlatformSpecific(PlatformID.Windows)] - public void CheckWindows() - { - Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); - Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("WINDOWS"))); - Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("windows"))); - Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("Windows NT"))); - Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)); - Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)); - } - [Fact, PlatformSpecific(PlatformID.Linux)] public void CheckLinux() { Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)); Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("LINUX"))); + + Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD"))); Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("linux"))); Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("UNIX"))); Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("DARWIN"))); @@ -34,14 +25,29 @@ public void CheckOSX() { Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)); Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("OSX"))); + + Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD"))); + Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)); Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("osx"))); Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("mac"))); Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("DARWIN"))); Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("MACOSX"))); - Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)); Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); } + [Fact, PlatformSpecific(PlatformID.Windows)] + public void CheckWindows() + { + Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("WINDOWS"))); + + Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD"))); + Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)); + Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)); + Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("windows"))); + Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("Windows NT"))); + } + [Fact] public void CheckOSPlatform() { @@ -56,12 +62,14 @@ public void CheckOSPlatform() Assert.True(winObj == winProp); Assert.True(winObj != randomObj); Assert.True(defaultObj == conObj); + Assert.False(winObj == defaultObj); Assert.False(winObj == randomObj); Assert.False(winObj != winProp); Assert.True(winObj.Equals(winProp)); Assert.True(conObj.Equals(defaultObj)); + Assert.False(defaultObj.Equals(winProp)); Assert.False(winObj.Equals(null)); Assert.False(winObj.Equals("something"));