@@ -20,33 +20,6 @@ namespace Polyfills;
2020static 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