static XmlDocumentationProvider LoadMscorlibDocumentation() { string xmlDocFile = FindXmlDocumentation("mscorlib.dll", MDHeaderRuntimeVersion.MS_CLR_40) ?? FindXmlDocumentation("mscorlib.dll", MDHeaderRuntimeVersion.MS_CLR_20); if (xmlDocFile != null) { return(XmlDocumentationProvider.Create(xmlDocFile)); } else { return(null); } }
private DocumentationProvider GetDocumentationProvider(string assemblyPath) { using (this.dataGuard.DisposableWait()) { assemblyPath = Path.ChangeExtension(assemblyPath, "xml"); DocumentationProvider provider; if (!this.assemblyPathToDocumentationProviderMap.TryGetValue(assemblyPath, out provider)) { provider = XmlDocumentationProvider.Create(assemblyPath); this.assemblyPathToDocumentationProviderMap.Add(assemblyPath, provider); } return(provider); } }
public static XmlDocumentationProvider LoadDocumentation(ModuleDef module) { if (module == null) { throw new ArgumentNullException("module"); } lock (cache) { XmlDocumentationProvider xmlDoc; if (!cache.TryGetValue(module, out xmlDoc)) { string xmlDocFile = LookupLocalizedXmlDoc(module.Location); if (xmlDocFile == null) { xmlDocFile = FindXmlDocumentation(Path.GetFileName(module.Location), module.RuntimeVersion); } xmlDoc = xmlDocFile == null ? null : XmlDocumentationProvider.Create(xmlDocFile); cache.Add(module, xmlDoc); } return(xmlDoc); } }
ProjectCompilation GetCompilation(int id) { Contract.Ensures(Contract.Result <ProjectCompilation>().IsValid); var state = _state; var compilation = _compilations.GetOrAdd(id, i => ProjectCompilation.Create(_state.Workspace.Projects.Single(p => p.Id == i).Name, i)); List <MetadataReference> references = null; Dictionary <int, int> projRefs = null; List <SyntaxTree> sources = null; ProjectEntry proj = null; ConfigurationData configData = null; CSharpParseOptions config = null; ProjectCompilation refComp; if (compilation.IsValid) { foreach (var projectRef in compilation.ProjectReferences) { refComp = GetCompilation(projectRef.Key); if (refComp.Version == projectRef.Value) { continue; } if (references == null) { references = new List <MetadataReference>(); } if (projRefs == null) { projRefs = new Dictionary <int, int>(); } references.Add(refComp.GetMetadataReference()); projRefs.Add(refComp.Id, refComp.Version); } if (references == null) { return(compilation); } } Workspace workspace = state.Workspace; proj = workspace.Projects.Single(p => p.Id == id); // TODO: Use "current configuration" configData = proj.Configurations.Single(c => c.FrameworkName == "net45"); Action <string> addAssembly = path => { if (!File.Exists(path)) { return; } DocumentationProvider doc = null; var docFile = Path.ChangeExtension(path, ".xml"); if (File.Exists(docFile)) { doc = XmlDocumentationProvider.Create(docFile); } references.Add(new MetadataFileReference(path, documentation: doc)); }; if (references != null || compilation.NeedsReferences) { if (references == null) { references = new List <MetadataReference>(); } if (projRefs == null) { projRefs = new Dictionary <int, int>(); } foreach (var package in proj.References) { if (package.Unresolved) { continue; } switch (package.Type) { case "Package": var path = Path.Combine(package.Path, "lib", proj.Configurations.Single(c => c.LongFrameworkName == package.Framework).FrameworkName); if (Directory.Exists(path)) { foreach (var file in Directory.EnumerateFiles(path, "*.dll", SearchOption.TopDirectoryOnly)) { addAssembly(file); } foreach (var file in Directory.EnumerateFiles(path, "*.exe", SearchOption.TopDirectoryOnly)) { addAssembly(file); } } break; case "Assembly": if (File.Exists(package.Path)) { addAssembly(package.Path); } else { // TODO: Implement assemblyneutral types } break; case "Project": // path is dir/project.json var pid = _projectLookup[Path.GetDirectoryName(package.Path)]; if (!projRefs.ContainsKey(pid)) { refComp = GetCompilation(pid); references.Add(refComp.GetMetadataReference()); projRefs.Add(pid, refComp.Version); } break; default: throw new ArgumentException("Unknown reference type"); } } } if (sources != null || compilation.NeedsSources) { if (config == null) { config = CSharpParseOptions.Default .WithLanguageVersion((LanguageVersion)configData.CompilationSettings.LanguageVersion) .WithPreprocessorSymbols(configData.CompilationSettings.Defines) .WithDocumentationMode(DocumentationMode.Parse); } if (sources == null) { sources = new List <SyntaxTree>(); } // TODO: Support generated files foreach (var source in proj.Sources) { var content = _contentDictionary.Values.SingleOrDefault(c => Path.Combine(workspace.Path, c.RelativePath) == source); if (content != null) { sources.Add(CSharpSyntaxTree.ParseText(content.ContentString, path: source, options: config)); } else { sources.Add(CSharpSyntaxTree.ParseFile(source, options: config)); } } } var newComp = compilation.Update(projRefs, references, sources); _compilations.TryUpdate(id, newComp, compilation); return(newComp); }
public DocumentationProvider GetDocumentationProvider(string assemblyPath) { if (assemblyPath == null) { throw new ArgumentNullException("assemblyPath"); } assemblyPath = Path.ChangeExtension(assemblyPath, "xml"); DocumentationProvider provider; if (!this.assemblyPathToDocumentationProviderMap.TryGetValue(assemblyPath, out provider)) { provider = this.assemblyPathToDocumentationProviderMap.GetOrAdd(assemblyPath, _path => XmlDocumentationProvider.Create(_path)); } return(provider); }