Get dependencies between classes in Roslyn

前端 未结 1 728
渐次进展
渐次进展 2021-02-06 08:41

I am successfully getting dependencies between projects with Roslyn, and now I would like to get dependencies between classes, similar to the Code Map feature in Visual Studio E

1条回答
  •  逝去的感伤
    2021-02-06 08:59

    I'm not sure about your requirements, but you can probably go for checking all descendant SyntaxNodes of the class and get the corresponding symbol, and it's type, and then collect these types. Something like the following:

    var semantic = compilation.GetSemanticModel(syntree);
    var typesForCurrentClass = classNode.DescendantNodes().Select(n => 
      semantic.GetTypeInfo(n).Type);
    

    Note that there can be multiple typesForCurrentClass for a given class symbol because of partial classes.

    0 讨论(0)
提交回复
热议问题