Roslyn Gets Class Dependencies

I am trying to determine for a class that it is referencing (other namespaces or namespaces of external libraries). It seems that because of the box for this document / syntaxtree etc., this is not the way to do it ... and much more that I just need to use character search, iterate over each file in the entire code base and call find, stick to found links on the map, and then navigating the map back.

Am I wrong here? Did I miss something? I'm just trying to build a dependency graph ... If I start with this class, then everything that ultimately needs to be recursive. I don't mind doing research, but I feel like something is missing ... and any guidance would be helpful

Brief concept of pseudocode:

var msWorkspace = MSBuildWorkspace.Create();
var solution = msWorkspace.OpenSolutionAsync(solutionPath).Result;
foreach (var project in solution.Projects)
{
    Append(project.Name);
    foreach (var document in project.Documents)
    {
        Append("\t\t\t" + document.Name);
        if (document.SupportsSemanticModel)
        {
            SemanticModel model = await document.GetSemanticModelAsync();
            var node = await document.GetSyntaxRootAsync();
            //Need to be able to gather dependencies for this current doc 
        }
     }
}
+4
1

, :

node.Descendents()
    .SelectMany(n => semanticModel.GetSymbols(n, workspace, true, new CancellationToken())
    .Distinct()
0

Source: https://habr.com/ru/post/1608186/


All Articles