Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions src/Polyfill/OperatingSystemCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

Expand Down Expand Up @@ -89,13 +90,8 @@ public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build =
return false;
}

if (windowsVersion == null)
{
var input = RuntimeInformation.OSDescription
.Replace("Microsoft Windows", string.Empty)
.Replace(" ", string.Empty);
windowsVersion = Version.Parse(input);
}
// e.g. "Microsoft Windows 10.0.19045 " or "Microsoft Windows 6.1.7601 Service Pack 1"
windowsVersion ??= ParseVersion(RuntimeInformation.OSDescription);

return windowsVersion >= new Version(major, minor, build, revision);
}
Expand Down Expand Up @@ -127,5 +123,33 @@ public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build =

return androidVersion >= new Version(major, minor, build, revision);
}

/// <summary>
/// Parses the first version number found in <paramref name="input"/>, ignoring any surrounding text.
/// Components that are not present are set to 0, so the result can be compared to a four part version.
/// </summary>
internal static Version ParseVersion(string input)
{
var start = 0;
while (start < input.Length && !char.IsDigit(input[start]))
{
start++;
}

var end = start;
while (end < input.Length && (char.IsDigit(input[end]) || input[end] == '.'))
{
end++;
}

var parts = input.Substring(start, end - start).Split(new[] {'.'}, StringSplitOptions.RemoveEmptyEntries);
var components = new int[4];
for (var index = 0; index < parts.Length && index < components.Length; index++)
{
components[index] = int.Parse(parts[index], CultureInfo.InvariantCulture);
}

return new(components[0], components[1], components[2], components[3]);
}
}
#endif
33 changes: 26 additions & 7 deletions src/Split/net461/OperatingSystemCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Polyfills;
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
[ExcludeFromCodeCoverage]
Expand Down Expand Up @@ -76,13 +77,7 @@ public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build =
{
return false;
}
if (windowsVersion == null)
{
var input = RuntimeInformation.OSDescription
.Replace("Microsoft Windows", string.Empty)
.Replace(" ", string.Empty);
windowsVersion = Version.Parse(input);
}
windowsVersion ??= ParseVersion(RuntimeInformation.OSDescription);
return windowsVersion >= new Version(major, minor, build, revision);
}
public static bool IsAndroid()
Expand All @@ -107,5 +102,29 @@ public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build =
}
return androidVersion >= new Version(major, minor, build, revision);
}
/// <summary>
/// Parses the first version number found in <paramref name="input"/>, ignoring any surrounding text.
/// Components that are not present are set to 0, so the result can be compared to a four part version.
/// </summary>
internal static Version ParseVersion(string input)
{
var start = 0;
while (start < input.Length && !char.IsDigit(input[start]))
{
start++;
}
var end = start;
while (end < input.Length && (char.IsDigit(input[end]) || input[end] == '.'))
{
end++;
}
var parts = input.Substring(start, end - start).Split(new[] {'.'}, StringSplitOptions.RemoveEmptyEntries);
var components = new int[4];
for (var index = 0; index < parts.Length && index < components.Length; index++)
{
components[index] = int.Parse(parts[index], CultureInfo.InvariantCulture);
}
return new(components[0], components[1], components[2], components[3]);
}
}
#endif
33 changes: 26 additions & 7 deletions src/Split/net462/OperatingSystemCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Polyfills;
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
[ExcludeFromCodeCoverage]
Expand Down Expand Up @@ -76,13 +77,7 @@ public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build =
{
return false;
}
if (windowsVersion == null)
{
var input = RuntimeInformation.OSDescription
.Replace("Microsoft Windows", string.Empty)
.Replace(" ", string.Empty);
windowsVersion = Version.Parse(input);
}
windowsVersion ??= ParseVersion(RuntimeInformation.OSDescription);
return windowsVersion >= new Version(major, minor, build, revision);
}
public static bool IsAndroid()
Expand All @@ -107,5 +102,29 @@ public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build =
}
return androidVersion >= new Version(major, minor, build, revision);
}
/// <summary>
/// Parses the first version number found in <paramref name="input"/>, ignoring any surrounding text.
/// Components that are not present are set to 0, so the result can be compared to a four part version.
/// </summary>
internal static Version ParseVersion(string input)
{
var start = 0;
while (start < input.Length && !char.IsDigit(input[start]))
{
start++;
}
var end = start;
while (end < input.Length && (char.IsDigit(input[end]) || input[end] == '.'))
{
end++;
}
var parts = input.Substring(start, end - start).Split(new[] {'.'}, StringSplitOptions.RemoveEmptyEntries);
var components = new int[4];
for (var index = 0; index < parts.Length && index < components.Length; index++)
{
components[index] = int.Parse(parts[index], CultureInfo.InvariantCulture);
}
return new(components[0], components[1], components[2], components[3]);
}
}
#endif
33 changes: 26 additions & 7 deletions src/Split/net47/OperatingSystemCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Polyfills;
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
[ExcludeFromCodeCoverage]
Expand Down Expand Up @@ -76,13 +77,7 @@ public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build =
{
return false;
}
if (windowsVersion == null)
{
var input = RuntimeInformation.OSDescription
.Replace("Microsoft Windows", string.Empty)
.Replace(" ", string.Empty);
windowsVersion = Version.Parse(input);
}
windowsVersion ??= ParseVersion(RuntimeInformation.OSDescription);
return windowsVersion >= new Version(major, minor, build, revision);
}
public static bool IsAndroid()
Expand All @@ -107,5 +102,29 @@ public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build =
}
return androidVersion >= new Version(major, minor, build, revision);
}
/// <summary>
/// Parses the first version number found in <paramref name="input"/>, ignoring any surrounding text.
/// Components that are not present are set to 0, so the result can be compared to a four part version.
/// </summary>
internal static Version ParseVersion(string input)
{
var start = 0;
while (start < input.Length && !char.IsDigit(input[start]))
{
start++;
}
var end = start;
while (end < input.Length && (char.IsDigit(input[end]) || input[end] == '.'))
{
end++;
}
var parts = input.Substring(start, end - start).Split(new[] {'.'}, StringSplitOptions.RemoveEmptyEntries);
var components = new int[4];
for (var index = 0; index < parts.Length && index < components.Length; index++)
{
components[index] = int.Parse(parts[index], CultureInfo.InvariantCulture);
}
return new(components[0], components[1], components[2], components[3]);
}
}
#endif
33 changes: 26 additions & 7 deletions src/Split/net471/OperatingSystemCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Polyfills;
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
[ExcludeFromCodeCoverage]
Expand Down Expand Up @@ -76,13 +77,7 @@ public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build =
{
return false;
}
if (windowsVersion == null)
{
var input = RuntimeInformation.OSDescription
.Replace("Microsoft Windows", string.Empty)
.Replace(" ", string.Empty);
windowsVersion = Version.Parse(input);
}
windowsVersion ??= ParseVersion(RuntimeInformation.OSDescription);
return windowsVersion >= new Version(major, minor, build, revision);
}
public static bool IsAndroid()
Expand All @@ -107,5 +102,29 @@ public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build =
}
return androidVersion >= new Version(major, minor, build, revision);
}
/// <summary>
/// Parses the first version number found in <paramref name="input"/>, ignoring any surrounding text.
/// Components that are not present are set to 0, so the result can be compared to a four part version.
/// </summary>
internal static Version ParseVersion(string input)
{
var start = 0;
while (start < input.Length && !char.IsDigit(input[start]))
{
start++;
}
var end = start;
while (end < input.Length && (char.IsDigit(input[end]) || input[end] == '.'))
{
end++;
}
var parts = input.Substring(start, end - start).Split(new[] {'.'}, StringSplitOptions.RemoveEmptyEntries);
var components = new int[4];
for (var index = 0; index < parts.Length && index < components.Length; index++)
{
components[index] = int.Parse(parts[index], CultureInfo.InvariantCulture);
}
return new(components[0], components[1], components[2], components[3]);
}
}
#endif
33 changes: 26 additions & 7 deletions src/Split/net472/OperatingSystemCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Polyfills;
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
[ExcludeFromCodeCoverage]
Expand Down Expand Up @@ -76,13 +77,7 @@ public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build =
{
return false;
}
if (windowsVersion == null)
{
var input = RuntimeInformation.OSDescription
.Replace("Microsoft Windows", string.Empty)
.Replace(" ", string.Empty);
windowsVersion = Version.Parse(input);
}
windowsVersion ??= ParseVersion(RuntimeInformation.OSDescription);
return windowsVersion >= new Version(major, minor, build, revision);
}
public static bool IsAndroid()
Expand All @@ -107,5 +102,29 @@ public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build =
}
return androidVersion >= new Version(major, minor, build, revision);
}
/// <summary>
/// Parses the first version number found in <paramref name="input"/>, ignoring any surrounding text.
/// Components that are not present are set to 0, so the result can be compared to a four part version.
/// </summary>
internal static Version ParseVersion(string input)
{
var start = 0;
while (start < input.Length && !char.IsDigit(input[start]))
{
start++;
}
var end = start;
while (end < input.Length && (char.IsDigit(input[end]) || input[end] == '.'))
{
end++;
}
var parts = input.Substring(start, end - start).Split(new[] {'.'}, StringSplitOptions.RemoveEmptyEntries);
var components = new int[4];
for (var index = 0; index < parts.Length && index < components.Length; index++)
{
components[index] = int.Parse(parts[index], CultureInfo.InvariantCulture);
}
return new(components[0], components[1], components[2], components[3]);
}
}
#endif
33 changes: 26 additions & 7 deletions src/Split/net48/OperatingSystemCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Polyfills;
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
[ExcludeFromCodeCoverage]
Expand Down Expand Up @@ -76,13 +77,7 @@ public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build =
{
return false;
}
if (windowsVersion == null)
{
var input = RuntimeInformation.OSDescription
.Replace("Microsoft Windows", string.Empty)
.Replace(" ", string.Empty);
windowsVersion = Version.Parse(input);
}
windowsVersion ??= ParseVersion(RuntimeInformation.OSDescription);
return windowsVersion >= new Version(major, minor, build, revision);
}
public static bool IsAndroid()
Expand All @@ -107,5 +102,29 @@ public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build =
}
return androidVersion >= new Version(major, minor, build, revision);
}
/// <summary>
/// Parses the first version number found in <paramref name="input"/>, ignoring any surrounding text.
/// Components that are not present are set to 0, so the result can be compared to a four part version.
/// </summary>
internal static Version ParseVersion(string input)
{
var start = 0;
while (start < input.Length && !char.IsDigit(input[start]))
{
start++;
}
var end = start;
while (end < input.Length && (char.IsDigit(input[end]) || input[end] == '.'))
{
end++;
}
var parts = input.Substring(start, end - start).Split(new[] {'.'}, StringSplitOptions.RemoveEmptyEntries);
var components = new int[4];
for (var index = 0; index < parts.Length && index < components.Length; index++)
{
components[index] = int.Parse(parts[index], CultureInfo.InvariantCulture);
}
return new(components[0], components[1], components[2], components[3]);
}
}
#endif
Loading
Loading