Finding all references to a method with Roslyn

asked10 years ago
last updated10 years ago
viewed20.7k times
Up Vote29Down Vote

I'm looking to scan a group of .cs files to see which ones call the Value property of a Nullable<T> (finding all references). For example, this would match:

class Program
{
    static void Main()
    {
        int? nullable = 123;
        int value = nullable.Value;
    }
}

I found out about Roslyn and looked at some of the samples, but many of them are outdated and the API is huge. How would I go about doing this?

I'm stuck after parsing the syntax tree. This is what I have so far:

public static void Analyze(string sourceCode)
{
    var tree = CSharpSyntaxTree.ParseText(sourceCode);

    tree./* ??? What goes here? */
}