Roslyn: Reconstruct code from BasicBlocks in a CFG

118 Views Asked by At

In Roslyn, a control flow graph has the list of BasicBlocks which constitute the program. Is it possible to get code statements from each block to reconstruct the entire code?

1

There are 1 best solutions below

0
On BEST ANSWER

This is not possible using Roslyn's in-built methods in my knowledge. I achieved a similar result by constructing a dictionary of blocks and sets of line numbers corresponding to those blocks using string matching. Additional filtering done to the same in order to improve accuracy in case of blocks that include locks etc. The result is not 100 percent accurate, but it comes pretty close in most cases.