diff --git a/src/System.Runtime.Environment/src/OSName.cs b/src/System.Runtime.Environment/src/OSName.cs deleted file mode 100644 index 84ca3ac0783e..000000000000 --- a/src/System.Runtime.Environment/src/OSName.cs +++ /dev/null @@ -1,61 +0,0 @@ -// 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 struct OSName : IEquatable - { - private readonly string _name; - - private const string WindowsName = "WINDOWS"; - private const string LinuxName = "LINUX"; - private const string OSXName = "OSX"; - - public static readonly OSName Windows = new OSName(WindowsName); - public static readonly OSName Linux = new OSName(LinuxName); - public static readonly OSName OSX = new OSName(OSXName); - - public OSName(string name) - { - if (name == null) throw new ArgumentNullException("name"); - if (name.Length == 0) throw new ArgumentException(SR.Argument_EmptyValue, "name"); - - _name = name; - } - - public bool Equals(OSName other) - { - return string.Equals(other._name, _name, StringComparison.Ordinal); - } - - public override bool Equals(object obj) - { - if (obj is OSName) - { - return Equals((OSName)obj); - } - - return false; - } - - public override int GetHashCode() - { - return _name == null ? 0 : _name.GetHashCode(); - } - - public override string ToString() - { - return _name ?? string.Empty; - } - - public static bool operator ==(OSName left, OSName right) - { - return left.Equals(right); - } - - public static bool operator !=(OSName left, OSName right) - { - return !(left == right); - } - } -} diff --git a/src/System.Runtime.Environment/tests/CheckPlatformTests.cs b/src/System.Runtime.Environment/tests/CheckPlatformTests.cs deleted file mode 100644 index 7807cd76454c..000000000000 --- a/src/System.Runtime.Environment/tests/CheckPlatformTests.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System.Runtime.InteropServices; -using Xunit; - -namespace System.Runtime.Environment.Tests -{ - public class CheckPlatformTests - { - [Fact, PlatformSpecific(PlatformID.Windows)] - public void CheckWindows() - { - Assert.True(RuntimeInformation.IsOperatingSystem(OSName.Windows)); - Assert.True(RuntimeInformation.IsOperatingSystem(new OSName("WINDOWS"))); - Assert.False(RuntimeInformation.IsOperatingSystem(new OSName("windows"))); - Assert.False(RuntimeInformation.IsOperatingSystem(new OSName("Windows NT"))); - Assert.False(RuntimeInformation.IsOperatingSystem(OSName.Linux)); - Assert.False(RuntimeInformation.IsOperatingSystem(OSName.OSX)); - } - - [Fact, PlatformSpecific(PlatformID.Linux)] - public void CheckLinux() - { - Assert.True(RuntimeInformation.IsOperatingSystem(OSName.Linux)); - Assert.True(RuntimeInformation.IsOperatingSystem(new OSName("LINUX"))); - Assert.False(RuntimeInformation.IsOperatingSystem(new OSName("linux"))); - Assert.False(RuntimeInformation.IsOperatingSystem(new OSName("UNIX"))); - Assert.False(RuntimeInformation.IsOperatingSystem(new OSName("ubuntu"))); - Assert.False(RuntimeInformation.IsOperatingSystem(OSName.Windows)); - Assert.False(RuntimeInformation.IsOperatingSystem(OSName.OSX)); - } - - [Fact, PlatformSpecific(PlatformID.OSX)] - public void CheckOSX() - { - Assert.True(RuntimeInformation.IsOperatingSystem(OSName.OSX)); - Assert.True(RuntimeInformation.IsOperatingSystem(new OSName("OSX"))); - Assert.False(RuntimeInformation.IsOperatingSystem(new OSName("osx"))); - Assert.False(RuntimeInformation.IsOperatingSystem(new OSName("mac"))); - Assert.False(RuntimeInformation.IsOperatingSystem(new OSName("MACOSX"))); - Assert.False(RuntimeInformation.IsOperatingSystem(OSName.Linux)); - Assert.False(RuntimeInformation.IsOperatingSystem(OSName.Windows)); - } - - [Fact] - public void CheckOSName() - { - OSName winObj = new OSName("WINDOWS"); - OSName winProp = OSName.Windows; - OSName randomObj = new OSName("random"); - OSName defaultObj = default(OSName); - OSName conObj = new OSName(); - Assert.Throws(() => { OSName nullObj = new OSName(null); }); - Assert.Throws(() => { OSName emptyObj = new OSName(""); }); - - 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")); - - Assert.Equal("WINDOWS", winObj.ToString()); - Assert.Equal("WINDOWS", winProp.ToString()); - Assert.Equal("", defaultObj.ToString()); - Assert.Equal("", conObj.ToString()); - Assert.Equal("random", randomObj.ToString()); - - Assert.Equal(winObj.GetHashCode(), winProp.GetHashCode()); - Assert.Equal(0, defaultObj.GetHashCode()); - Assert.Equal(defaultObj.GetHashCode(), conObj.GetHashCode()); - } - } -} diff --git a/src/System.Runtime.Environment/System.Runtime.Environment.sln b/src/System.Runtime.InteropServices.RuntimeInformation/System.Runtime.InteropServices.RuntimeInformation.sln similarity index 92% rename from src/System.Runtime.Environment/System.Runtime.Environment.sln rename to src/System.Runtime.InteropServices.RuntimeInformation/System.Runtime.InteropServices.RuntimeInformation.sln index d52b1a590a73..b10ca0b23bc1 100644 --- a/src/System.Runtime.Environment/System.Runtime.Environment.sln +++ b/src/System.Runtime.InteropServices.RuntimeInformation/System.Runtime.InteropServices.RuntimeInformation.sln @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.22609.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.Environment", "src\System.Runtime.Environment.csproj", "{F9DF2357-81B4-4317-908E-512DA9395583}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.InteropServices.RuntimeInformation", "src\System.Runtime.InteropServices.RuntimeInformation.csproj", "{F9DF2357-81B4-4317-908E-512DA9395583}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.Environment.Tests", "tests\System.Runtime.Environment.Tests.csproj", "{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.InteropServices.RuntimeInformation.Tests", "tests\System.Runtime.InteropServices.RuntimeInformation.Tests.csproj", "{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/System.Runtime.InteropServices.RuntimeInformation/src/OSPlatform.cs b/src/System.Runtime.InteropServices.RuntimeInformation/src/OSPlatform.cs new file mode 100644 index 000000000000..39e6e2ecb56e --- /dev/null +++ b/src/System.Runtime.InteropServices.RuntimeInformation/src/OSPlatform.cs @@ -0,0 +1,90 @@ +// 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 struct OSPlatform : IEquatable + { + private readonly string _osPlatform; + + private const string WindowsName = "WINDOWS"; + private const string LinuxName = "LINUX"; + private const string OSXName = "OSX"; + + private static readonly OSPlatform s_windows = new OSPlatform(WindowsName); + private static readonly OSPlatform s_linux = new OSPlatform(LinuxName); + private static readonly OSPlatform s_osx = new OSPlatform(OSXName); + + public static OSPlatform Windows + { + get + { + return s_windows; + } + } + + public static OSPlatform Linux + { + get + { + return s_linux; + } + } + + public static OSPlatform OSX + { + get + { + return s_osx; + } + } + + private OSPlatform(string osPlatform) + { + if (osPlatform == null) throw new ArgumentNullException("name"); + if (osPlatform.Length == 0) throw new ArgumentException(SR.Argument_EmptyValue, "name"); + + _osPlatform = osPlatform; + } + + public static OSPlatform Create(string osPlatform) + { + return new OSPlatform(osPlatform); + } + + public bool Equals(OSPlatform other) + { + return string.Equals(other._osPlatform, _osPlatform, StringComparison.Ordinal); + } + + public override bool Equals(object obj) + { + if (obj is OSPlatform) + { + return Equals((OSPlatform)obj); + } + + return false; + } + + public override int GetHashCode() + { + return _osPlatform == null ? 0 : _osPlatform.GetHashCode(); + } + + public override string ToString() + { + return _osPlatform ?? string.Empty; + } + + public static bool operator ==(OSPlatform left, OSPlatform right) + { + return left.Equals(right); + } + + public static bool operator !=(OSPlatform left, OSPlatform right) + { + return !(left == right); + } + } +} diff --git a/src/System.Runtime.Environment/src/Resources/Strings.resx b/src/System.Runtime.InteropServices.RuntimeInformation/src/Resources/Strings.resx similarity index 100% rename from src/System.Runtime.Environment/src/Resources/Strings.resx rename to src/System.Runtime.InteropServices.RuntimeInformation/src/Resources/Strings.resx diff --git a/src/System.Runtime.Environment/src/RuntimeInformation.Linux.cs b/src/System.Runtime.InteropServices.RuntimeInformation/src/RuntimeInformation.Linux.cs similarity index 70% rename from src/System.Runtime.Environment/src/RuntimeInformation.Linux.cs rename to src/System.Runtime.InteropServices.RuntimeInformation/src/RuntimeInformation.Linux.cs index fba35175e006..ad60328e2640 100644 --- a/src/System.Runtime.Environment/src/RuntimeInformation.Linux.cs +++ b/src/System.Runtime.InteropServices.RuntimeInformation/src/RuntimeInformation.Linux.cs @@ -5,9 +5,9 @@ namespace System.Runtime.InteropServices { public static class RuntimeInformation { - public static bool IsOperatingSystem(OSName osName) + public static bool IsOSPlatform(OSPlatform osPlatform) { - return OSName.Linux == osName; + return OSPlatform.Linux == osPlatform; } } } diff --git a/src/System.Runtime.Environment/src/RuntimeInformation.OSX.cs b/src/System.Runtime.InteropServices.RuntimeInformation/src/RuntimeInformation.OSX.cs similarity index 71% rename from src/System.Runtime.Environment/src/RuntimeInformation.OSX.cs rename to src/System.Runtime.InteropServices.RuntimeInformation/src/RuntimeInformation.OSX.cs index bef0f8680325..c96e196d6971 100644 --- a/src/System.Runtime.Environment/src/RuntimeInformation.OSX.cs +++ b/src/System.Runtime.InteropServices.RuntimeInformation/src/RuntimeInformation.OSX.cs @@ -5,9 +5,9 @@ namespace System.Runtime.InteropServices { public static class RuntimeInformation { - public static bool IsOperatingSystem(OSName osName) + public static bool IsOSPlatform(OSPlatform osPlatform) { - return OSName.OSX == osName; + return OSPlatform.OSX == osPlatform; } } } diff --git a/src/System.Runtime.Environment/src/RuntimeInformation.Windows.cs b/src/System.Runtime.InteropServices.RuntimeInformation/src/RuntimeInformation.Windows.cs similarity index 70% rename from src/System.Runtime.Environment/src/RuntimeInformation.Windows.cs rename to src/System.Runtime.InteropServices.RuntimeInformation/src/RuntimeInformation.Windows.cs index 198279c9d18c..eed96af0f6d1 100644 --- a/src/System.Runtime.Environment/src/RuntimeInformation.Windows.cs +++ b/src/System.Runtime.InteropServices.RuntimeInformation/src/RuntimeInformation.Windows.cs @@ -5,9 +5,9 @@ namespace System.Runtime.InteropServices { public static class RuntimeInformation { - public static bool IsOperatingSystem(OSName osName) + public static bool IsOSPlatform(OSPlatform osPlatform) { - return OSName.Windows == osName; + return OSPlatform.Windows == osPlatform; } } } diff --git a/src/System.Runtime.Environment/src/System.Runtime.Environment.csproj b/src/System.Runtime.InteropServices.RuntimeInformation/src/System.Runtime.InteropServices.RuntimeInformation.csproj similarity index 93% rename from src/System.Runtime.Environment/src/System.Runtime.Environment.csproj rename to src/System.Runtime.InteropServices.RuntimeInformation/src/System.Runtime.InteropServices.RuntimeInformation.csproj index 6d49d5ff2e22..8c1f6e714599 100644 --- a/src/System.Runtime.Environment/src/System.Runtime.Environment.csproj +++ b/src/System.Runtime.InteropServices.RuntimeInformation/src/System.Runtime.InteropServices.RuntimeInformation.csproj @@ -6,7 +6,7 @@ AnyCPU Library System.Runtime.InteropServices - System.Runtime.Environment + System.Runtime.InteropServices.RuntimeInformation 4.0.0.0 {F9DF2357-81B4-4317-908E-512DA9395583} @@ -30,7 +30,7 @@ - + \ No newline at end of file diff --git a/src/System.Runtime.Environment/src/project.json b/src/System.Runtime.InteropServices.RuntimeInformation/src/project.json similarity index 100% rename from src/System.Runtime.Environment/src/project.json rename to src/System.Runtime.InteropServices.RuntimeInformation/src/project.json diff --git a/src/System.Runtime.Environment/src/project.lock.json b/src/System.Runtime.InteropServices.RuntimeInformation/src/project.lock.json similarity index 100% rename from src/System.Runtime.Environment/src/project.lock.json rename to src/System.Runtime.InteropServices.RuntimeInformation/src/project.lock.json diff --git a/src/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs b/src/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs new file mode 100644 index 000000000000..2303945c2ffe --- /dev/null +++ b/src/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs @@ -0,0 +1,80 @@ +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("linux"))); + Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("UNIX"))); + Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("DARWIN"))); + Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("ubuntu"))); + Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)); + } + + [Fact, PlatformSpecific(PlatformID.OSX)] + public void CheckOSX() + { + Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)); + Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("OSX"))); + 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] + public void CheckOSPlatform() + { + OSPlatform winObj = OSPlatform.Create("WINDOWS"); + OSPlatform winProp = OSPlatform.Windows; + OSPlatform randomObj = OSPlatform.Create("random"); + OSPlatform defaultObj = default(OSPlatform); + OSPlatform conObj = new OSPlatform(); + Assert.Throws(() => { OSPlatform nullObj = OSPlatform.Create(null); }); + Assert.Throws(() => { OSPlatform emptyObj = OSPlatform.Create(""); }); + + 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")); + + Assert.Equal("WINDOWS", winObj.ToString()); + Assert.Equal("WINDOWS", winProp.ToString()); + Assert.Equal("", defaultObj.ToString()); + Assert.Equal("", conObj.ToString()); + Assert.Equal("random", randomObj.ToString()); + + Assert.Equal(winObj.GetHashCode(), winProp.GetHashCode()); + Assert.Equal(0, defaultObj.GetHashCode()); + Assert.Equal(defaultObj.GetHashCode(), conObj.GetHashCode()); + } + } +} diff --git a/src/System.Runtime.Environment/tests/System.Runtime.Environment.Tests.csproj b/src/System.Runtime.InteropServices.RuntimeInformation/tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj similarity index 75% rename from src/System.Runtime.Environment/tests/System.Runtime.Environment.Tests.csproj rename to src/System.Runtime.InteropServices.RuntimeInformation/tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj index 4fd13c930e90..df104bd7a6ba 100644 --- a/src/System.Runtime.Environment/tests/System.Runtime.Environment.Tests.csproj +++ b/src/System.Runtime.InteropServices.RuntimeInformation/tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj @@ -7,8 +7,8 @@ AnyCPU Library Properties - System.Runtime.Environment.Tests - System.Runtime.Environment.Tests + System.Runtime.InteropServices.RuntimeInformation.Tests + System.Runtime.InteropServices.RuntimeInformation.Tests {9B4D1DA9-AA4C-428F-9F66-D45C924025A5} @@ -20,9 +20,9 @@ - - {f9df2357-81b4-4317-908e-512da9395583} - System.Runtime.Environment + + {F9DF2357-81B4-4317-908E-512DA9395583} + System.Runtime.InteropServices.RuntimeInformation diff --git a/src/System.Runtime.Environment/tests/project.json b/src/System.Runtime.InteropServices.RuntimeInformation/tests/project.json similarity index 100% rename from src/System.Runtime.Environment/tests/project.json rename to src/System.Runtime.InteropServices.RuntimeInformation/tests/project.json diff --git a/src/System.Runtime.Environment/tests/project.lock.json b/src/System.Runtime.InteropServices.RuntimeInformation/tests/project.lock.json similarity index 100% rename from src/System.Runtime.Environment/tests/project.lock.json rename to src/System.Runtime.InteropServices.RuntimeInformation/tests/project.lock.json