Skip to content

Commit 45c3227

Browse files
committed
Update OperatingSystemPolyfill.cs
1 parent b7d85d6 commit 45c3227

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

src/Polyfill/OperatingSystemPolyfill.cs

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,6 @@ static class OperatingSystemPolyfill
2121
{
2222
#if !NET5_0_OR_GREATER
2323

24-
static Version GetFreeBSDVersion()
25-
{
26-
if (!IsFreeBSD())
27-
{
28-
return Environment.OSVersion.Version;
29-
}
30-
31-
var version = Environment.OSVersion.VersionString
32-
.Replace("Unix", string.Empty).Replace("FreeBSD", string.Empty)
33-
.Replace("-release", string.Empty).Replace(" ", string.Empty);
34-
35-
return Version.Parse(version);
36-
}
37-
38-
static Version GetAndroidVersion()
39-
{
40-
if (!IsAndroid())
41-
{
42-
return Environment.OSVersion.Version;
43-
}
44-
45-
var result = RunProcess("getprop", "ro.build.version.release")
46-
.Replace(" ", string.Empty);
47-
48-
return Version.Parse(result);
49-
}
50-
5124
static string RunProcess(string name, string arguments)
5225
{
5326
using var process = new Process()
@@ -244,12 +217,27 @@ public static bool IsFreeBSD() =>
244217
/// <param name="revision">The version revision number.</param>
245218
/// <returns>true if the current application is running on a FreeBSD version that is at least what was specified in the parameters; false otherwise.</returns>
246219
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.isfreebsdversionatleast
247-
public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0) =>
220+
public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0)
221+
{
248222
#if NET5_0_OR_GREATER
249-
OperatingSystem.IsFreeBSDVersionAtLeast(major, minor, build, revision);
223+
return OperatingSystem.IsFreeBSDVersionAtLeast(major, minor, build, revision);
250224
#else
251-
GetFreeBSDVersion() >= new Version(major, minor, build, revision);
225+
if (!IsFreeBSD())
226+
{
227+
return false;
228+
}
229+
230+
var versionString = Environment.OSVersion.VersionString
231+
.Replace("Unix", string.Empty)
232+
.Replace("FreeBSD", string.Empty)
233+
.Replace("-release", string.Empty)
234+
.Replace(" ", string.Empty);
235+
236+
var version = Version.Parse(versionString);
237+
238+
return version >= new Version(major, minor, build, revision);
252239
#endif
240+
}
253241

254242
/// <summary>
255243
/// Indicates whether the current application is running on iOS or MacCatalyst.
@@ -346,13 +334,24 @@ public static bool IsAndroid()
346334
/// <param name="revision">The revision release number.</param>
347335
/// <returns>true if the current application is running on an Android version that is at least what was specified in the parameters; false otherwise.</returns>
348336
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.isandroidversionatleast
349-
public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) =>
337+
public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0)
338+
{
350339
#if NET5_0_OR_GREATER
351-
OperatingSystem.IsAndroidVersionAtLeast(major, minor, build, revision);
340+
return OperatingSystem.IsAndroidVersionAtLeast(major, minor, build, revision);
352341
#else
353-
IsAndroid() &&
354-
GetAndroidVersion() >= new Version(major, minor, build, revision);
342+
if (!IsAndroid())
343+
{
344+
return false;
345+
}
346+
347+
var result = RunProcess("getprop", "ro.build.version.release")
348+
.Replace(" ", string.Empty);
349+
350+
var version = Version.Parse(result);
351+
352+
return version >= new Version(major, minor, build, revision);
355353
#endif
354+
}
356355

357356
/// <summary>
358357
/// Indicates whether the current application is running on watchOS.

0 commit comments

Comments
 (0)