NetPlatformHelper
Class is used by the NetPlatformAttribute class to
determine whether a platform is supported.
using System;
using System.Linq;
using System.Runtime.CompilerServices;
namespace NUnit.Framework.Internal
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public static class NetPlatformHelper
{
private static readonly char[] Digits = new char[10] {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9'
};
public static bool IsPlatformSupported(string[] platforms)
{
return platforms.Any(IsPlatformSupported);
}
public static bool IsPlatformSupported(string platform)
{
if (platform.Contains(','))
return IsPlatformSupported(platform.Split(',', StringSplitOptions.None));
string plaformName = platform.Trim();
ParseOSAndVersion(plaformName, out string os, out Version version);
if ((object)version != null && os.Equals("Windows", StringComparison.OrdinalIgnoreCase)) {
if (version.Major == 7)
version = new Version(6, 1);
else if (version.Major == 8) {
version = new Version(6, (version.Minor == 1) ? 3 : 2);
}
}
if ((object)version != null)
return OperatingSystem.IsOSPlatformVersionAtLeast(os, version.Major, version.Minor, version.Build, version.MajorRevision);
return OperatingSystem.IsOSPlatform(os);
}
private static void ParseOSAndVersion(string plaformName, out string os, [System.Runtime.CompilerServices.Nullable(2)] out Version version)
{
int num = plaformName.IndexOfAny(Digits);
if (num > 0) {
os = plaformName.Substring(0, num);
Version.TryParse(plaformName.Substring(num), out version);
} else {
os = plaformName;
version = null;
}
}
}
}