<PackageReference Include="NUnit" Version="4.2.2" />

OSPlatformConverter

static class OSPlatformConverter
Converts .NET6+ OSPlatformAttribute to NetPlatformAttribute which can be applied to tests.
using NUnit.Framework.Interfaces; using System; using System.Collections.Generic; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; namespace NUnit.Framework { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] internal static class OSPlatformConverter { public static IEnumerable<IApplyToTest> RetrieveAndConvert(this ICustomAttributeProvider provider) { IApplyToTest[] attributes = provider.GetAttributes<IApplyToTest>(true); OSPlatformAttribute[] attributes2 = provider.GetAttributes<OSPlatformAttribute>(true); return Convert(attributes2, attributes); } internal static IEnumerable<IApplyToTest> Convert(OSPlatformAttribute[] osPlatformAttributes, IApplyToTest[] applyToTestAttributes) { HashSet<string> includes = new HashSet<string>(StringComparer.OrdinalIgnoreCase); HashSet<string> excludes = new HashSet<string>(StringComparer.OrdinalIgnoreCase); foreach (IApplyToTest applyToTest in applyToTestAttributes) { NetPlatformAttribute netPlatformAttribute = applyToTest as NetPlatformAttribute; if (netPlatformAttribute != null) { <Convert>g__Add|1_0(includes, netPlatformAttribute.Include); <Convert>g__Add|1_0(excludes, netPlatformAttribute.Exclude); } else yield return applyToTest; } foreach (OSPlatformAttribute oSPlatformAttribute in osPlatformAttributes) { string platformName = oSPlatformAttribute.PlatformName; if (oSPlatformAttribute is SupportedOSPlatformAttribute) includes.Add(platformName); else if (oSPlatformAttribute is UnsupportedOSPlatformAttribute) { excludes.Add(platformName); } } if (includes.Count > 0 || excludes.Count > 0) yield return (IApplyToTest)new NetPlatformAttribute { Include = ((includes.Count == 0) ? null : string.Join(",", includes)), Exclude = ((excludes.Count == 0) ? null : string.Join(",", excludes)) }; } } }