I need to get some sort of a dependency graph between classes of a given project i.e. all the classes which that specific class uses. I want to know which classes a given class is using so that I can later find their file path within a project. Consider the following simple example:
public class Dog: Animal, IBark
{
public void Bark()
{
// Code to bark.
}
public void Fight(Cat cat)
{
// Code to fight cat.
}
}
For this specific example, I would like to know which classes the Dog
class uses. So I would like to programmatically get access to an object that has those dependencies. In this situation, that object would contain the IBark
, Animal
and Cat
classes/interfaces and possibly their respective file paths.
Is this possible in C#? I have tried looking into the Roslyn API and although I can parse the document and traverse it to find the nodes I have not found a way to get metadata related to those nodes that could possibly give me what I am looking for (e.g. file paths). This got me wondering if there is not a better approach to this problem out there.