Roslyn-动态(运行时)流程 [英] Roslyn - dynamic (runtime) flow
问题描述
我开始和罗斯林一起玩。解析代码和进行静态分析相对容易。
I started playing with Roslyn. It’s relatively easy to parse code and do static analysis.
我想知道是否可以将其用于运行时分析?我想调用带有参数的方法,并检查执行了哪些分支。换句话说,我需要一个运行时执行计划。
Roslyn可以解决吗?
I wonder if it’s possible to use it for runtime analysis? I want to call a method with parameters and check which branches were executed. In other words, I need a runtime execution plan. Is it something which could be done with Roslyn?
推荐答案
我不知道什么是最好的解决方案是,在大多数情况下,我会遵从SLaks的建议。
I don't know what the best solution is and I would defer to anything SLaks recommends in most cases.
但是...
如果您想和Roslyn一起做,那就一定可以。实际上,在我公司中,我们做了类似的事情(我们将单元测试映射到他们调用的方法)。
If you want to do this with Roslyn you certainly can. In fact at my company does something similar (we map unit tests to the methods they invoke).
以下是我们方法的高级概述。
Here's a high level overview of our approach.
-
重写解决方案中的每个函数,以在某些全局静态查找/数据结构中被击中时进行记录。您可以一次遍历每个文件,并对每个文件使用
CSharpSyntaxRewriter
。 (在您的情况下,您将在分支或逐行的基础上进行重写)
Rewrite every single function in the solution to log when it is hit in some global static lookup/data-structure. You can iterate over every file one at a time and use the
CSharpSyntaxRewriter
on each one. (In your case you'll be rewriting on a branch or line-by-line basis)
一次运行每个单元测试,看看会得到什么
Run each unit test one at a time and see what gets run by analzying your global lookup.
汇总所有单元测试的结果以了解完整的代码覆盖范围。
Aggregate the results across all your unit tests to understand your complete code coverage.
这篇关于Roslyn-动态(运行时)流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!