How to find all instances of types that implement a given interface during debugging

雨燕双飞 提交于 2019-11-30 11:50:42

A few years ago, I was desperate for some information like this. I ended up creating a treeview that would only appear when you used an obscure option for starting the app. When I clicked "refresh", it would use reflection to travel through all the properties of the root class instance. If it found a property that was a collection or held other properties, it would recursively call into them. The end result was that a tree of the instance data at that point was available for perusal.

The main points to this approach are

  1. Make sure you have only one top-level object instance, or you know exactly how many and which top-level instances there are. (Also, don't forget about static values.)
  2. Figure out how to use reflection to look through the relevant bits of information.
  3. Display it when needed and in a readable fashion.

Have you tried

!dumpheap -type IFaces

It will show the method tables too. You can dig deeper from there.

Your best bet would be to start with Crack.NET, which does some of what you want to do (although it targets wpf and winforms apps). The project is open source so you should be able to derive the method used to get the information you want from the source. It has a plugin that for Reflector that allows you to inspect the details of an in memory object as well.

Project page: http://joshsmithonwpf.wordpress.com/cracknet/

CodePlex: http://cracknetproject.codeplex.com/

If you don't have to create your own program, try NDepend.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!