Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 11 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
为了正确地做到这一点,您需要一个 C# 应用程序的全局调用图,使用 C# 语义和相当于点分析的内容进行计算,可以说包括它调用的库。使用这样的调用图,您可以枚举其中的循环,这些循环将是要检查的候选者。
我不知道从哪里可以获得现成的 C# 全局调用图计算工具。
您可以使用简单的代码扫描技术来近似这一点。对于每个方法 M,提取它包含的明显调用集作为标识符 I。大多数情况下,它们将显示为类似于 identifier( 的语法。在此步骤之后,您将获得 M_i -> I。您可以构建此作为一个(极其保守的)基本调用图,然后计算传递闭包,您将获得一个带有循环的近似调用图,并且您可以执行循环分析,这将通过名称和其他情况传递大量方法。但这可能已经足够好了。
To do this right, you need a global call graph over the C# application, computed using C# semantics and what amounts to a points-to analysis, arguably including the libraries it calls. With such a call graph, you could enumerate the cycles in it, and those would be the candidates to check.
I don't know where you would get a tool that compute such a global call graph for C#, off the shelf.
You could approximate this using simple code scanning techniques. For each method M, extract the apparant set of calls it contains as identifiers I. Mostly they will appear as syntax that looks like identifier( After this step you have M_i -> I. You can build this as an (extermely conservative) basic call graph, and then compute the transitive closure. With that, you have an approximate call graph with cycles, and you can carry out your cycle analysis. This would mass methods passed by names, and other cases, but it might be good enough.
Gendarme 将捕获一些(最常见但基本的)递归情况。 MS FxCop 也有一些(IIRC)。然而,(目前)都没有规则来涵盖更复杂的情况,例如:M1->M2->M3->M1...
遗憾的是,我不知道有任何其他工具可以为.NET 进行此类检测。请分享您发现的任何内容:-)
Gendarme will catch some (the most common, but basic) cases of recursions. MS FxCop has some too (IIRC). However neither have rules (presently) to cover more complex cases like: M1->M2->M3->M1...
Sadly I'm not aware of any other tool that can do such detection for .NET. Please share anything you find :-)