public static async Task <string> Generate(DirectoryInfo directory, TextWriter writer, bool generateStatistics = false) { var aggregator = new StyleAggregator(); async Task AnalyzeFilesAsync(DirectoryInfo rootDirectory) { writer.WriteLine($"Analyzing {rootDirectory}..."); foreach (var file in rootDirectory.EnumerateFiles()) { if (file.Extension.ToLower() == ".cs") { writer.WriteLine($"\tAnalyzing {file.FullName}..."); var(unit, model) = StyleGenerator.GetCompilationInformation(file.FullName); aggregator = aggregator.Update(new StyleAggregator().Add(unit, model)); } } foreach (var subDirectory in rootDirectory.EnumerateDirectories()) { await AnalyzeFilesAsync(subDirectory); } } await AnalyzeFilesAsync(directory); if (generateStatistics) { using var statisticsWriter = File.CreateText("statistics.json"); new JsonSerializer().Serialize(statisticsWriter, aggregator); } return(aggregator.GenerateConfiguration()); }
public static string GenerateFromDocument(FileInfo document, TextWriter writer, bool generateStatistics = false) { if (document.Extension.ToLower() == ".cs") { writer.WriteLine($"Analyzing {document.FullName}..."); var(unit, model) = StyleGenerator.GetCompilationInformation(document.FullName); var aggregator = new StyleAggregator().Add(unit, model); if (generateStatistics) { using var statisticsWriter = File.CreateText("statistics.json"); new JsonSerializer().Serialize(statisticsWriter, aggregator); } return(aggregator.GenerateConfiguration()); } return(string.Empty); }