通过反射查找属性使用量 [英] Finding property usage counts with reflection

查看:152
本文介绍了通过反射查找属性使用量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成的文件,大约有10,000个公共静态属性和方法。我怀疑它们的数量并不完全没有使用,但是大约有50个程序集和数百万行代码可以确定。



我想要做运行某种实用工具,可以查看我们所有的编译程序集,并告诉我这个类的哪些成员被调用,并给我每一个。



反思有可能是这样的事情,还是需要恢复到实际的代码分析工具?是否有任何库可以分析程序集以在另一个程序集中查找其依赖项?

解决方案

ReSharper查找使用高级功能可以在库和当前解决方案中找到参考。我没有使用这个特殊功能,所以我不知道它的工作效果如何(在解决方案中查找使用效果相当不错),但是您可以获得ReSharper的试用版,然后尝试一下。我的猜测是,您需要从具有项目的解决方案中运行它,并引用您感兴趣的各种库。


I have a generated file with around 10,000 public static properties and methods. I suspect that a nontrivial number of them are entirely unused, but there are around 50 assemblies and millions of lines of code to check to be sure.

What I would like to do is run some kind of utility that can look into all of the compiled assemblies we have and tell me exactly which members of this class are being called, and give me counts for each one.

Is such a thing possible with reflection, or do I need to revert to actual code analysis tools? Are there any libraries that can analyze assemblies to find their dependencies within another assembly?

解决方案

The ReSharper "Find Usages Advanced" feature has an option to find references in Libraries as well as in the current Solution. I haven't used this particular feature, so I'm not sure how well it works (the Find Usages within a solution works quite nicely), but you can get a trial version of ReSharper and try it. My guess is that you'll need to run it from a Solution that has a Project with references to the various Libraries you're interested in.

这篇关于通过反射查找属性使用量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆