public IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context) { // Get syntax trees (supply path so that XML doc includes can be resolved) ConcurrentBag <SyntaxTree> syntaxTrees = new ConcurrentBag <SyntaxTree>(); Parallel.ForEach(inputs, input => { using (Stream stream = input.GetStream()) { SourceText sourceText = SourceText.From(stream); syntaxTrees.Add(CSharpSyntaxTree.ParseText(sourceText, path: input.String(Keys.SourceFilePath, string.Empty))); } }); // Create the compilation (have to supply an XmlReferenceResolver to handle include XML doc comments) MetadataReference mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location); CSharpCompilation compilation = CSharpCompilation .Create("CodeAnalysisModule", syntaxTrees) .WithReferences(mscorlib) .WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, xmlReferenceResolver: new XmlFileResolver(context.FileSystem.RootPath.FullPath))); // Get and return the document tree AnalyzeSymbolVisitor visitor = new AnalyzeSymbolVisitor(context, _symbolPredicate, _writePath ?? (x => DefaultWritePath(x, _writePathPrefix)), _cssClasses, _docsForImplicitSymbols); visitor.Visit(compilation.Assembly.GlobalNamespace); return(visitor.Finish()); }
public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context) { // Get syntax trees (supply path so that XML doc includes can be resolved) ConcurrentBag<SyntaxTree> syntaxTrees = new ConcurrentBag<SyntaxTree>(); Parallel.ForEach(inputs, input => { using (Stream stream = input.GetStream()) { SourceText sourceText = SourceText.From(stream); syntaxTrees.Add(CSharpSyntaxTree.ParseText(sourceText, path: input.String(Keys.SourceFilePath, string.Empty))); } }); // Create the compilation (have to supply an XmlReferenceResolver to handle include XML doc comments) MetadataReference mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location); CSharpCompilation compilation = CSharpCompilation .Create("CodeAnalysisModule", syntaxTrees) .WithReferences(mscorlib) .WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, xmlReferenceResolver: new XmlFileResolver(context.FileSystem.RootPath.FullPath))); // Get and return the document tree AnalyzeSymbolVisitor visitor = new AnalyzeSymbolVisitor(context, _symbolPredicate, _writePath ?? (x => DefaultWritePath(x, _writePathPrefix)), _cssClasses, _docsForImplicitSymbols); visitor.Visit(compilation.Assembly.GlobalNamespace); return visitor.Finish(); }
/// <inheritdoc /> public IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context) { // Create the compilation (have to supply an XmlReferenceResolver to handle include XML doc comments) MetadataReference mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location); Compilation compilation = CSharpCompilation .Create(CompilationAssemblyName) .WithReferences(mscorlib) .WithOptions(new CSharpCompilationOptions( OutputKind.DynamicallyLinkedLibrary, xmlReferenceResolver: new XmlFileResolver(context.FileSystem.RootPath.FullPath))); // Add the input source and references List <ISymbol> symbols = new List <ISymbol>(); compilation = AddSourceFiles(inputs, context, compilation); compilation = AddProjectReferences(context, symbols, compilation); compilation = AddSolutionReferences(context, symbols, compilation); compilation = AddAssemblyReferences(context, symbols, compilation); // Get and return the document tree symbols.Add(compilation.Assembly.GlobalNamespace); AnalyzeSymbolVisitor visitor = new AnalyzeSymbolVisitor( compilation, context, _symbolPredicate, _writePath ?? (x => DefaultWritePath(x, _writePathPrefix)), _cssClasses, _docsForImplicitSymbols, _assemblySymbols, _implicitInheritDoc); foreach (ISymbol symbol in symbols) { visitor.Visit(symbol); } return(visitor.Finish()); }
public SymbolDocumentValue(ISymbol symbol, AnalyzeSymbolVisitor visitor) { _symbol = symbol; _visitor = visitor; }
public IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context) { List <ISymbol> symbols = new List <ISymbol>(); // Create the compilation (have to supply an XmlReferenceResolver to handle include XML doc comments) MetadataReference mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location); Compilation compilation = CSharpCompilation .Create(CompilationAssemblyName) .WithReferences(mscorlib) .WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, xmlReferenceResolver: new XmlFileResolver(context.FileSystem.RootPath.FullPath))); // Handle input documents if (_inputDocuments) { // Get syntax trees (supply path so that XML doc includes can be resolved) ConcurrentBag <SyntaxTree> syntaxTrees = new ConcurrentBag <SyntaxTree>(); context.ParallelForEach(inputs, input => { using (Stream stream = input.GetStream()) { SourceText sourceText = SourceText.From(stream); syntaxTrees.Add(CSharpSyntaxTree.ParseText(sourceText, path: input.String(Keys.SourceFilePath, string.Empty))); } }); compilation = compilation.AddSyntaxTrees(syntaxTrees); } // Handle assemblies IEnumerable <IFile> assemblyFiles = context.FileSystem.GetInputFiles(_assemblyGlobs) .Where(x => (x.Path.Extension == ".dll" || x.Path.Extension == ".exe") && x.Exists); MetadataReference[] assemblyReferences = assemblyFiles.Select(assemblyFile => { // Create the metadata reference for the compilation IFile xmlFile = context.FileSystem.GetFile(assemblyFile.Path.ChangeExtension("xml")); if (xmlFile.Exists) { Trace.Verbose($"Creating metadata reference for assembly {assemblyFile.Path.FullPath} with XML documentation file"); using (Stream xmlStream = xmlFile.OpenRead()) { using (MemoryStream xmlBytes = new MemoryStream()) { xmlStream.CopyTo(xmlBytes); return(MetadataReference.CreateFromStream(assemblyFile.OpenRead(), documentation: XmlDocumentationProvider.CreateFromBytes(xmlBytes.ToArray()))); } } } Trace.Verbose($"Creating metadata reference for assembly {assemblyFile.Path.FullPath} without XML documentation file"); return((MetadataReference)MetadataReference.CreateFromStream(assemblyFile.OpenRead())); }).ToArray(); if (assemblyReferences.Length > 0) { compilation = compilation.AddReferences(assemblyReferences); symbols.AddRange(assemblyReferences .Select(x => (IAssemblySymbol)compilation.GetAssemblyOrModuleSymbol(x)) .Select(x => _assemblySymbols ? x : (ISymbol)x.GlobalNamespace)); } // Get and return the document tree symbols.Add(compilation.Assembly.GlobalNamespace); AnalyzeSymbolVisitor visitor = new AnalyzeSymbolVisitor(compilation, context, _symbolPredicate, _writePath ?? (x => DefaultWritePath(x, _writePathPrefix)), _cssClasses, _docsForImplicitSymbols, _assemblySymbols); foreach (ISymbol symbol in symbols) { visitor.Visit(symbol); } return(visitor.Finish()); }
public SymbolDocumentValues(IEnumerable <ISymbol> symbols, AnalyzeSymbolVisitor visitor) { _symbols = symbols ?? Array.Empty <ISymbol>(); _visitor = visitor; }
public SymbolDocumentValues(IEnumerable<ISymbol> symbols, AnalyzeSymbolVisitor visitor) { _symbols = symbols ?? Array.Empty<ISymbol>(); _visitor = visitor; }