Roslyn method survey - Indexing methods by types found in their signatures

I wanted to survey a whole codebase and identify methods whose signatures (defined simply as return type + parameter types) were similar. As well as identifying methods whose signature matched exactly (public int X(string arg) and public int Y(string anotherArg) are fundamentally string -> int) I wanted to identify methods whose signatures shared some components, like X: string -> int and Y: IEnumerable<string> -> int[], which share both string and int.

Modifying my previous method survey code was fairly straightforward. I built a lookup from a string type representation to a list of matching methods. Expanding the components of generic types needed a bit of thought, and I tackled it with a recursive call that broke down type parameters (on the assumption that all generic types were INamedTypeSymbols):

Here I’m using LanguageExt again to lay this out in a more functional style.

Then it’s a matter of going through each document; extracting MethodDeclarationSyntax nodes; and then extracting and expanding either parameter of return types:

ValueTuples aren’t handled well in this current form: although you can reference them in detail (e.g. (int first, int second)) you can’t specify them as, say a Tuple<int, int>, although you can search for ValueTuple and deduce from there which methods are of interest. Moreover, it doesn’t expand types to hierarchies or interfaces, which would be potentially useful.