/// <summary> /// Gets the <see cref="TargetFramework"/> for the specified <paramref name="module"/>. /// </summary> /// <param name="module">The module to get the target framework description for. Cannot be null.</param> /// <returns>A new instance of the <see cref="TargetFramework"/> class that describes the specified <paramref name="module"/>. /// </returns> public static TargetFramework DetectTargetFramework(PEFile module) { if (module is null) { throw new ArgumentNullException(nameof(module)); } int versionNumber; switch (module.GetRuntime()) { case TargetRuntime.Net_1_0: versionNumber = 100; break; case TargetRuntime.Net_1_1: versionNumber = 110; break; case TargetRuntime.Net_2_0: versionNumber = 200; // TODO: Detect when .NET 3.0/3.5 is required break; default: versionNumber = 400; break; } string targetFrameworkIdentifier = null; string targetFrameworkProfile = null; string targetFramework = module.DetectTargetFrameworkId(); if (!string.IsNullOrEmpty(targetFramework)) { string[] frameworkParts = targetFramework.Split(','); targetFrameworkIdentifier = frameworkParts.FirstOrDefault(a => !a.StartsWith(VersionToken, StringComparison.OrdinalIgnoreCase) && !a.StartsWith(ProfileToken, StringComparison.OrdinalIgnoreCase)); string frameworkVersion = frameworkParts.FirstOrDefault(a => a.StartsWith(VersionToken, StringComparison.OrdinalIgnoreCase)); if (frameworkVersion != null) { versionNumber = int.Parse(frameworkVersion.Substring(VersionToken.Length + 1).Replace(".", "")); if (versionNumber < 100) { versionNumber *= 10; } } string frameworkProfile = frameworkParts.FirstOrDefault(a => a.StartsWith(ProfileToken, StringComparison.OrdinalIgnoreCase)); if (frameworkProfile != null) { targetFrameworkProfile = frameworkProfile.Substring(ProfileToken.Length); } } return(new TargetFramework(targetFrameworkIdentifier, versionNumber, targetFrameworkProfile)); }
private TargetFramework DetectTargetFramework(PEFile module) { TargetFramework result = default; switch (module.GetRuntime()) { case Metadata.TargetRuntime.Net_1_0: result.VersionNumber = 100; result.TargetFrameworkVersion = "v1.0"; break; case Metadata.TargetRuntime.Net_1_1: result.VersionNumber = 110; result.TargetFrameworkVersion = "v1.1"; break; case Metadata.TargetRuntime.Net_2_0: result.VersionNumber = 200; result.TargetFrameworkVersion = "v2.0"; // TODO: Detect when .NET 3.0/3.5 is required break; default: result.VersionNumber = 400; result.TargetFrameworkVersion = "v4.0"; break; } string targetFramework = module.Reader.DetectTargetFrameworkId(); if (!string.IsNullOrEmpty(targetFramework)) { string[] frameworkParts = targetFramework.Split(','); result.TargetFrameworkIdentifier = frameworkParts.FirstOrDefault(a => !a.StartsWith("Version=", StringComparison.OrdinalIgnoreCase) && !a.StartsWith("Profile=", StringComparison.OrdinalIgnoreCase)); string frameworkVersion = frameworkParts.FirstOrDefault(a => a.StartsWith("Version=", StringComparison.OrdinalIgnoreCase)); if (frameworkVersion != null) { result.TargetFrameworkVersion = frameworkVersion.Substring("Version=".Length); result.VersionNumber = int.Parse(frameworkVersion.Substring("Version=v".Length).Replace(".", "")); if (result.VersionNumber < 100) { result.VersionNumber *= 10; } } string frameworkProfile = frameworkParts.FirstOrDefault(a => a.StartsWith("Profile=", StringComparison.OrdinalIgnoreCase)); if (frameworkProfile != null) { result.TargetFrameworkProfile = frameworkProfile.Substring("Profile=".Length); } } return(result); }
public static XmlDocumentationProvider LoadDocumentation(PEFile module) { if (module == null) { throw new ArgumentNullException(nameof(module)); } lock (cache) { XmlDocumentationProvider xmlDoc; if (!cache.TryGetValue(module, out xmlDoc)) { string xmlDocFile = LookupLocalizedXmlDoc(module.FileName); if (xmlDocFile == null) { xmlDocFile = FindXmlDocumentation(Path.GetFileName(module.FileName), module.GetRuntime()); } if (xmlDocFile != null) { xmlDoc = new XmlDocumentationProvider(xmlDocFile); cache.Add(module, xmlDoc); } else { cache.Add(module, null); // add missing documentation files as well xmlDoc = null; } } return(xmlDoc); } }