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

RuntimeFramework

public sealed class RuntimeFramework
RuntimeFramework represents a particular version of a common language runtime implementation.
using Microsoft.Win32; using System; using System.IO; using System.Reflection; namespace NUnit.Framework.Internal { [Serializable] public sealed class RuntimeFramework { public static readonly Version DefaultVersion = new Version(0, 0); private static RuntimeFramework currentFramework; public static RuntimeFramework CurrentFramework { get { if (currentFramework == null) { Type type = Type.GetType("Mono.Runtime", false); bool num = Type.GetType("MonoTouch.UIKit.UIApplicationDelegate,monotouch") != (Type)null; bool flag = type != (Type)null; RuntimeType runtime = num ? RuntimeType.MonoTouch : (flag ? RuntimeType.Mono : ((Environment.OSVersion.Platform != PlatformID.WinCE) ? RuntimeType.Net : RuntimeType.NetCF)); int num2 = Environment.Version.Major; int minor = Environment.Version.Minor; if (!flag) { switch (num2) { case 2: using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\.NETFramework")) { if (registryKey != null) { string text = registryKey.GetValue("InstallRoot") as string; if (text != null) { if (Directory.Exists(Path.Combine(text, "v3.5"))) { num2 = 3; minor = 5; } else if (Directory.Exists(Path.Combine(text, "v3.0"))) { num2 = 3; minor = 0; } } } } break; case 4: if (Type.GetType("System.Reflection.AssemblyMetadataAttribute") != (Type)null) minor = 5; break; } } else { switch (num2) { case 1: minor = 0; break; case 2: num2 = 3; minor = 5; break; } } currentFramework = new RuntimeFramework(runtime, new Version(num2, minor)); currentFramework.ClrVersion = Environment.Version; if (flag) { MethodInfo method = type.GetMethod("GetDisplayName", BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.ExactBinding); if (method != (MethodInfo)null) currentFramework.DisplayName = (string)method.Invoke(null, new object[0]); } } return currentFramework; } } public RuntimeType Runtime { get; set; } public Version FrameworkVersion { get; set; } public Version ClrVersion { get; set; } public bool AllowAnyVersion => ClrVersion == DefaultVersion; public string DisplayName { get; set; } public RuntimeFramework(RuntimeType runtime, Version version) { Runtime = runtime; if (version.Build < 0) InitFromFrameworkVersion(version); else InitFromClrVersion(version); DisplayName = GetDefaultDisplayName(runtime, version); } private void InitFromFrameworkVersion(Version version) { Version version4 = FrameworkVersion = (ClrVersion = version); if (version.Major > 0) { switch (Runtime) { case RuntimeType.SSCLI: break; case RuntimeType.Any: case RuntimeType.Net: case RuntimeType.Mono: switch (version.Major) { case 1: switch (version.Minor) { case 0: ClrVersion = ((Runtime == RuntimeType.Mono) ? new Version(1, 1, 4322) : new Version(1, 0, 3705)); break; case 1: if (Runtime == RuntimeType.Mono) FrameworkVersion = new Version(1, 0); ClrVersion = new Version(1, 1, 4322); break; default: ThrowInvalidFrameworkVersion(version); break; } break; case 2: case 3: ClrVersion = new Version(2, 0, 50727); break; case 4: ClrVersion = new Version(4, 0, 30319); break; default: ThrowInvalidFrameworkVersion(version); break; } break; case RuntimeType.Silverlight: ClrVersion = ((version.Major >= 4) ? new Version(4, 0, 60310) : new Version(2, 0, 50727)); break; case RuntimeType.NetCF: { int major = version.Major; if (major == 3) { major = version.Minor; if (major == 5) ClrVersion = new Version(3, 5, 7283); } break; } } } } private static void ThrowInvalidFrameworkVersion(Version version) { throw new ArgumentException("Unknown framework version " + version.ToString(), "version"); } private void InitFromClrVersion(Version version) { FrameworkVersion = new Version(version.Major, version.Minor); ClrVersion = version; if (Runtime == RuntimeType.Mono && version.Major == 1) FrameworkVersion = new Version(1, 0); } public static RuntimeFramework Parse(string s) { RuntimeType runtime = RuntimeType.Any; Version version = DefaultVersion; string[] array = s.Split(new char[1] { '-' }); if (array.Length == 2) { runtime = (RuntimeType)Enum.Parse(typeof(RuntimeType), array[0], true); string text = array[1]; if (text != "") version = new Version(text); } else if (char.ToLower(s[0]) == 'v') { version = new Version(s.Substring(1)); } else if (IsRuntimeTypeName(s)) { runtime = (RuntimeType)Enum.Parse(typeof(RuntimeType), s, true); } else { version = new Version(s); } return new RuntimeFramework(runtime, version); } public override string ToString() { RuntimeType runtime; if (AllowAnyVersion) { runtime = Runtime; return runtime.ToString().ToLower(); } string text = FrameworkVersion.ToString(); if (Runtime == RuntimeType.Any) return "v" + text; runtime = Runtime; return runtime.ToString().ToLower() + "-" + text; } public bool Supports(RuntimeFramework target) { if (Runtime != 0 && target.Runtime != 0 && Runtime != target.Runtime) return false; if (AllowAnyVersion || target.AllowAnyVersion) return true; if (!VersionsMatch(ClrVersion, target.ClrVersion)) return false; if (Runtime != RuntimeType.Silverlight) { if (FrameworkVersion.Major >= target.FrameworkVersion.Major) return FrameworkVersion.Minor >= target.FrameworkVersion.Minor; return false; } if (FrameworkVersion.Major == target.FrameworkVersion.Major) return FrameworkVersion.Minor == target.FrameworkVersion.Minor; return false; } private static bool IsRuntimeTypeName(string name) { string[] enumNames = TypeHelper.GetEnumNames(typeof(RuntimeType)); for (int i = 0; i < enumNames.Length; i++) { if (enumNames[i].ToLower() == name.ToLower()) return true; } return false; } private static string GetDefaultDisplayName(RuntimeType runtime, Version version) { if (version == DefaultVersion) return runtime.ToString(); if (runtime == RuntimeType.Any) return "v" + version.ToString(); return runtime.ToString() + " " + version.ToString(); } private static bool VersionsMatch(Version v1, Version v2) { if (v1.Major == v2.Major && v1.Minor == v2.Minor && (v1.Build < 0 || v2.Build < 0 || v1.Build == v2.Build)) { if (v1.Revision >= 0 && v2.Revision >= 0) return v1.Revision == v2.Revision; return true; } return false; } } }