Roslyn method survey - Building an index of method signatures
Given a CSharp solution I wanted to ask which methods shared the same signature. It’s possible to load a solution using MsBuild and produce a set of documents that can be analysed using Roslyn’s Syntax API - and running through that analysis is fairly straightforward, with a bit of detail around method signature comparison.
Taking the documents
collection produced by loading a solution it’s easy to extract a tuple holding parameters, return type and method name (if you’re looking for Map
, you can replace with Select
– I just picked up the LanguageExt.Core
NuGet):
I can then build a lookup from method signature to a list of methods – after defining what I think of as a method signature. I decided to take the return type and a list of the parameter types, using a clunky first-cut EquivalentTo
method to compare lists of parameter types, because two methods might define parameters in a different order:
EquivalentTo
as I say is a little clunky, but serves:
The end result signatureLookup
is lookup from a method signature (as parameter type list and return type) to a list of methods expressing that signature, that you can then use as you want; for example, to build an ordered list of signature : method list mappings: