Skip to content

Commit b7d85d6

Browse files
committed
cleanup
1 parent 9267304 commit b7d85d6

File tree

2 files changed

+57
-36
lines changed

2 files changed

+57
-36
lines changed

readme.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The package targets `netstandard2.0` and is designed to support the following ru
1212
* `net5.0`, `net6.0`, `net7.0`, `net8.0`, `net9.0`
1313

1414

15-
**API count: 460**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->
15+
**API count: 481**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->
1616

1717

1818
**See [Milestones](../../milestones?state=closed) for release notes.**
@@ -1019,6 +1019,31 @@ The class `Polyfill` includes the following extension methods:
10191019
* `bool TryParse(string?, IFormatProvider?, long)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryparse#system-int64-tryparse(system-string-system-iformatprovider-system-int64@))
10201020

10211021

1022+
#### OperatingSystemPolyfill
1023+
1024+
* `bool IsAndroid()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.isandroid)
1025+
* `bool IsAndroidVersionAtLeast(int, int, int, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.isandroidversionatleast)
1026+
* `bool IsBrowser()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.isbrowser)
1027+
* `bool IsFreeBSD()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.isfreebsd)
1028+
* `bool IsFreeBSDVersionAtLeast(int, int, int, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.isfreebsdversionatleast)
1029+
* `bool IsIOS()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.isios)
1030+
* `bool IsIOSVersionAtLeast(int, int, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.isiosversionatleast)
1031+
* `bool IsLinux()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.islinux)
1032+
* `bool IsMacCatalyst()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.ismaccatalyst)
1033+
* `bool IsMacCatalystVersionAtLeast(int, int, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.ismaccatalystversionatleast)
1034+
* `bool IsMacOS()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.ismacos)
1035+
* `bool IsMacOSVersionAtLeast(int, int, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.ismacosversionatleast)
1036+
* `bool IsOSPlatform(string)`
1037+
* `bool IsOSPlatformVersionAtLeast(string, int, int, int, int)`
1038+
* `bool IsTvOS()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.istvos)
1039+
* `bool IsTvOSVersionAtLeast(int, int, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.istvosversionatleast)
1040+
* `bool IsWasi()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.iswasi)
1041+
* `bool IsWatchOS()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.iswatchos)
1042+
* `bool IsWatchOSVersionAtLeast(int, int, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.iswatchosversionatleast)
1043+
* `bool IsWindows()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.iswindows)
1044+
* `bool IsWindowsVersionAtLeast(int, int, int, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.iswindowsversionatleast)
1045+
1046+
10221047
#### PathPolyfill
10231048

10241049
* `string Combine(ReadOnlySpan<string>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.path.combine#system-io-path-combine(system-readonlyspan((system-string))))

src/Polyfill/OperatingSystemPolyfill.cs

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,6 @@ namespace Polyfills;
2020
static class OperatingSystemPolyfill
2121
{
2222
#if !NET5_0_OR_GREATER
23-
static Version GetWindowsVersion()
24-
{
25-
if (IsWindows())
26-
{
27-
var input = RuntimeInformation.OSDescription
28-
.Replace("Microsoft Windows", string.Empty)
29-
.Replace(" ", string.Empty);
30-
return Version.Parse(input);
31-
}
32-
33-
return Environment.OSVersion.Version;
34-
}
35-
36-
static Version GetMacOSVersion()
37-
{
38-
if (!IsMacOS())
39-
{
40-
return Environment.OSVersion.Version;
41-
}
42-
43-
var version = RunProcess("/usr/bin/sw_vers", "")
44-
.Replace("ProductVersion:", string.Empty)
45-
.Replace(" ", string.Empty);
46-
47-
return Version.Parse(version.Split(Environment.NewLine.ToCharArray())[0]);
48-
49-
}
5023

5124
static Version GetFreeBSDVersion()
5225
{
@@ -149,13 +122,24 @@ public static bool IsWindows() =>
149122
/// <param name="revision">The revision release number.</param>
150123
/// <returns>true if the current application is running on a Windows version that is at least what was specified in the parameters; false otherwise.</returns>
151124
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.iswindowsversionatleast
152-
public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) =>
125+
public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0)
126+
{
153127
#if NET5_0_OR_GREATER
154-
OperatingSystem.IsWindowsVersionAtLeast(major, minor, build, revision);
128+
return OperatingSystem.IsWindowsVersionAtLeast(major, minor, build, revision);
155129
#else
156-
IsWindows() &&
157-
GetWindowsVersion() >= new Version(major, minor, build, revision);
130+
if (!IsWindows())
131+
{
132+
return false;
133+
}
134+
135+
var input = RuntimeInformation.OSDescription
136+
.Replace("Microsoft Windows", string.Empty)
137+
.Replace(" ", string.Empty);
138+
var version = Version.Parse(input);
139+
140+
return version >= new Version(major, minor, build, revision);
158141
#endif
142+
}
159143

160144
/// <summary>
161145
/// Indicates whether the current application is running on macOS.
@@ -190,13 +174,25 @@ public static bool IsMacCatalyst() =>
190174
/// <param name="build">The build release number.</param>
191175
/// <returns>true if the current application is running on an macOS version that is at least what was specified in the parameters; false otherwise.</returns>
192176
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.ismacosversionatleast
193-
public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0) =>
177+
public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0)
178+
{
194179
#if NET5_0_OR_GREATER
195-
OperatingSystem.IsMacOSVersionAtLeast(major, minor, build);
180+
return OperatingSystem.IsMacOSVersionAtLeast(major, minor, build);
196181
#else
197-
IsMacOS() &&
198-
GetMacOSVersion() >= new Version(major, minor, build);
182+
if (!IsMacOS())
183+
{
184+
return false;
185+
}
186+
187+
var versionString = RunProcess("/usr/bin/sw_vers", "")
188+
.Replace("ProductVersion:", string.Empty)
189+
.Replace(" ", string.Empty);
190+
191+
var version = Version.Parse(versionString.Split(Environment.NewLine.ToCharArray())[0]);
192+
193+
return version >= new Version(major, minor, build);
199194
#endif
195+
}
200196

201197
/// <summary>
202198
/// Check for the Mac Catalyst version (iOS version as presented in Apple documentation) with a ≤ version comparison. Used to guard APIs that were added in the given Mac Catalyst release.

0 commit comments

Comments
 (0)