attempting to generate UML sequence diagrams

Topics: APIs, C# Language Design, General
Apr 22, 2014 at 9:10 PM
Edited Apr 22, 2014 at 9:10 PM
I would appreciate any criticism or advice anyone has to offer here..

I thought it would be fun to use Roslyn to generate UML sequence diagrams ( leveraging this awesome javascript library: )

Here's some code I threw together to try to understand how I can get a list of methods and track all invocations of those methods:

I feel like I'm getting off track where I call ProcessClass (if not sooner).

Also curious how to access invocations through extension methods, methods in static classes and methods with ref/out parameters? I can see methods with ref/out parameters in the invocation list, but can't seem to find anything with an Identifier. What am I doing wrong?

How could I go about calls to external libraries?
Apr 23, 2014 at 4:04 PM
May have figured this out (other than for methods with ref/out params)... looks like I may not be traversing the full syntax tree for each method reference. Will try using FindReferencesAsync.
Apr 23, 2014 at 5:46 PM
Two notes:
  • Do not use async void. This will cause exceptions to be silently swallowed. Also, if you didn't have the Console.ReadKey() your program would immediately terminate because we do not wait for an async void to return. Use async Task instead.
  • SymbolFinder.FindCallersAsync may be helpful since you won't have to write any of the logic to traverse the tree to find InvocationExpressionSyntax nodes.
Apr 23, 2014 at 7:36 PM
Edited Apr 23, 2014 at 7:39 PM
thanks.. I came up with a solution using FindReferencesAsync (see here), but will try FindCallersAsync. Thanks for the async advice. I've traditionally used Tasks so I've just been playing around with async, but was not sure I was using it properly!
Marked as answer by s3Logic on 4/23/2014 at 12:40 PM
Jul 11, 2014 at 3:11 PM

I made something similar - to find the reference chain out from a method token. you can check it out here.
It's a bit tricky when using FindReferencesAsync as it return references from abstract definitions, which depending on the implementation may result in cyclic references. I had to use transitive closure to build the graph.

Jul 14, 2014 at 11:03 AM
I haven't had time to do anything beyond what I did here:
It would be nice to extend this to work with external assemblies, but currently starting two businesses so I won't have time for a while!