/// <summary> /// Parse C# codes in csproj files. /// </summary> /// <param name="csProjDirPath">Directory path included csproj file.</param> /// <param name="compileType">Type of project.</param> public void Parse(CsprojAnalyzer csprojAnalyzer) { if (!Directory.Exists(csprojAnalyzer.CsprojParentPath)) { return; } var csFilesInfo = csprojAnalyzer.GetCsFiles(); var syntaxTrees = new List <SyntaxTree>(); int index = 0; foreach (var tuple in csFilesInfo.SourceFiles.Select((v, i) => new { Value = v, Index = i })) { var text = File.ReadAllText(tuple.Value).UnifiedNewLine(); var namespaceItem = GetNamespace(text); syntaxTrees.Add(CSharpSyntaxTree.ParseText(text, CSharpParseOptions.Default, tuple.Value)); AnalysisProgress?.Invoke(this, new CSharpParseProgressEventArgs( CSharpParseProgressEventArgs.ParseType.SyntacticAnalysis, csFilesInfo.SourceFiles.Length * 2, ++index, tuple.Value)); } var metadataReferences = new List <MetadataReference> { { csFilesInfo.References, (item) => MetadataReference.CreateFromFile(item.Location) } }; var compilation = CSharpCompilation.Create("sample", syntaxTrees, metadataReferences); foreach (var tuple in syntaxTrees.Select((v, i) => new { Value = v, Index = i })) { RoslynAnalyze(tuple.Value, compilation); AnalysisProgress?.Invoke(this, new CSharpParseProgressEventArgs( CSharpParseProgressEventArgs.ParseType.CodeAnalysis, csFilesInfo.SourceFiles.Length * 2, ++index, tuple.Value.FilePath)); } CodeAnalysisCompleted?.Invoke(this, new EventArgs()); }
public virtual void OnAnalysisProgress(ProgressEventArgs e) { AnalysisProgress?.Invoke(this, e); }