Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit e3296d3

Browse files
Merge pull request #1999 from Priya91/updateOSPlatform
Add OSVersion APIs to .NET Core
2 parents 6dba5e5 + e84ac58 commit e3296d3

15 files changed

+185
-154
lines changed

src/System.Runtime.Environment/src/OSName.cs

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/System.Runtime.Environment/tests/CheckPlatformTests.cs

Lines changed: 0 additions & 78 deletions
This file was deleted.

src/System.Runtime.Environment/System.Runtime.Environment.sln renamed to src/System.Runtime.InteropServices.RuntimeInformation/System.Runtime.InteropServices.RuntimeInformation.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
44
VisualStudioVersion = 14.0.22609.0
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.Environment", "src\System.Runtime.Environment.csproj", "{F9DF2357-81B4-4317-908E-512DA9395583}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.InteropServices.RuntimeInformation", "src\System.Runtime.InteropServices.RuntimeInformation.csproj", "{F9DF2357-81B4-4317-908E-512DA9395583}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.Environment.Tests", "tests\System.Runtime.Environment.Tests.csproj", "{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.InteropServices.RuntimeInformation.Tests", "tests\System.Runtime.InteropServices.RuntimeInformation.Tests.csproj", "{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace System.Runtime.InteropServices
5+
{
6+
public struct OSPlatform : IEquatable<OSPlatform>
7+
{
8+
private readonly string _osPlatform;
9+
10+
private const string WindowsName = "WINDOWS";
11+
private const string LinuxName = "LINUX";
12+
private const string OSXName = "OSX";
13+
14+
private static readonly OSPlatform s_windows = new OSPlatform(WindowsName);
15+
private static readonly OSPlatform s_linux = new OSPlatform(LinuxName);
16+
private static readonly OSPlatform s_osx = new OSPlatform(OSXName);
17+
18+
public static OSPlatform Windows
19+
{
20+
get
21+
{
22+
return s_windows;
23+
}
24+
}
25+
26+
public static OSPlatform Linux
27+
{
28+
get
29+
{
30+
return s_linux;
31+
}
32+
}
33+
34+
public static OSPlatform OSX
35+
{
36+
get
37+
{
38+
return s_osx;
39+
}
40+
}
41+
42+
private OSPlatform(string osPlatform)
43+
{
44+
if (osPlatform == null) throw new ArgumentNullException("name");
45+
if (osPlatform.Length == 0) throw new ArgumentException(SR.Argument_EmptyValue, "name");
46+
47+
_osPlatform = osPlatform;
48+
}
49+
50+
public static OSPlatform Create(string osPlatform)
51+
{
52+
return new OSPlatform(osPlatform);
53+
}
54+
55+
public bool Equals(OSPlatform other)
56+
{
57+
return string.Equals(other._osPlatform, _osPlatform, StringComparison.Ordinal);
58+
}
59+
60+
public override bool Equals(object obj)
61+
{
62+
if (obj is OSPlatform)
63+
{
64+
return Equals((OSPlatform)obj);
65+
}
66+
67+
return false;
68+
}
69+
70+
public override int GetHashCode()
71+
{
72+
return _osPlatform == null ? 0 : _osPlatform.GetHashCode();
73+
}
74+
75+
public override string ToString()
76+
{
77+
return _osPlatform ?? string.Empty;
78+
}
79+
80+
public static bool operator ==(OSPlatform left, OSPlatform right)
81+
{
82+
return left.Equals(right);
83+
}
84+
85+
public static bool operator !=(OSPlatform left, OSPlatform right)
86+
{
87+
return !(left == right);
88+
}
89+
}
90+
}

src/System.Runtime.Environment/src/RuntimeInformation.Linux.cs renamed to src/System.Runtime.InteropServices.RuntimeInformation/src/RuntimeInformation.Linux.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ namespace System.Runtime.InteropServices
55
{
66
public static class RuntimeInformation
77
{
8-
public static bool IsOperatingSystem(OSName osName)
8+
public static bool IsOSPlatform(OSPlatform osPlatform)
99
{
10-
return OSName.Linux == osName;
10+
return OSPlatform.Linux == osPlatform;
1111
}
1212
}
1313
}

src/System.Runtime.Environment/src/RuntimeInformation.OSX.cs renamed to src/System.Runtime.InteropServices.RuntimeInformation/src/RuntimeInformation.OSX.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ namespace System.Runtime.InteropServices
55
{
66
public static class RuntimeInformation
77
{
8-
public static bool IsOperatingSystem(OSName osName)
8+
public static bool IsOSPlatform(OSPlatform osPlatform)
99
{
10-
return OSName.OSX == osName;
10+
return OSPlatform.OSX == osPlatform;
1111
}
1212
}
1313
}

src/System.Runtime.Environment/src/RuntimeInformation.Windows.cs renamed to src/System.Runtime.InteropServices.RuntimeInformation/src/RuntimeInformation.Windows.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ namespace System.Runtime.InteropServices
55
{
66
public static class RuntimeInformation
77
{
8-
public static bool IsOperatingSystem(OSName osName)
8+
public static bool IsOSPlatform(OSPlatform osPlatform)
99
{
10-
return OSName.Windows == osName;
10+
return OSPlatform.Windows == osPlatform;
1111
}
1212
}
1313
}

src/System.Runtime.Environment/src/System.Runtime.Environment.csproj renamed to src/System.Runtime.InteropServices.RuntimeInformation/src/System.Runtime.InteropServices.RuntimeInformation.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
77
<OutputType>Library</OutputType>
88
<RootNamespace>System.Runtime.InteropServices</RootNamespace>
9-
<AssemblyName>System.Runtime.Environment</AssemblyName>
9+
<AssemblyName>System.Runtime.InteropServices.RuntimeInformation</AssemblyName>
1010
<AssemblyVersion>4.0.0.0</AssemblyVersion>
1111
<ProjectGuid>{F9DF2357-81B4-4317-908E-512DA9395583}</ProjectGuid>
1212
</PropertyGroup>
@@ -30,7 +30,7 @@
3030
<None Include="project.json" />
3131
</ItemGroup>
3232
<ItemGroup>
33-
<Compile Include="OSName.cs" />
33+
<Compile Include="OSPlatform.cs" />
3434
</ItemGroup>
3535
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
3636
</Project>

0 commit comments

Comments
 (0)