Beispiel #1
0
        public static ProjectsData AnalyseSolution(string solutionPath)
        {
            ProjectsData     result      = new ProjectsData();
            MSBuildWorkspace msWorkspace = MSBuildWorkspace.Create();

            try
            {
                Solution solution = msWorkspace.OpenSolutionAsync(solutionPath).Result;
                foreach (Project project in solution.Projects)
                {
                    Compilation compilation = project.GetCompilationAsync().Result;
                    foreach (Document document in project.Documents)
                    {
                        SyntaxNode root = document.GetSyntaxRootAsync().Result;

                        var          nodes       = root.DescendantNodes(n => true);
                        var          st          = root.SyntaxTree;
                        var          sm          = compilation.GetSemanticModel(st);
                        SyntaxNode[] syntaxNodes = nodes as SyntaxNode[] ?? nodes.ToArray();

                        IEnumerable <ITypeSymbol> symbolsReferenced = GetReferencedSymbols(sm, syntaxNodes);
                        IEnumerable <ITypeSymbol> symbolsDeclared   = GetClassDeclarations(sm, syntaxNodes);
                        result.AddReferencedTypes(project.Name, symbolsReferenced.Select(x => x.ToDisplayString()));
                        result.AddDeclaredTypes(project.Name, symbolsDeclared.Select(x => x.ToDisplayString()));
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(result);
        }
Beispiel #2
0
        public static ProjectsData Merge(ProjectsData p1, ProjectsData p2)
        {
            ProjectsData result = new ProjectsData();

            p1.referencedTypesByProj.ToList().ForEach(x => result.referencedTypesByProj[x.Key] = x.Value);
            p2.referencedTypesByProj.ToList().ForEach(x => result.referencedTypesByProj[x.Key] = x.Value);
            p1.declaredTypesByProj.ToList().ForEach(x => result.declaredTypesByProj[x.Key]     = x.Value);
            p2.declaredTypesByProj.ToList().ForEach(x => result.declaredTypesByProj[x.Key]     = x.Value);
            return(result);
        }