如何获取实现给定接口的所有加载类型的所有实例? [英] How do I get all instances of all loaded types that implement a given interface?

查看:15
本文介绍了如何获取实现给定接口的所有加载类型的所有实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要获取实现给定接口的对象的所有实例 - 我们可以这样做吗?如果可以,该怎么做?

We need to get all the instances of objects that implement a given interface - can we do that, and if so how?

推荐答案

我不相信有办法...你要么能够遍历堆,检查那里的每个对象,要么遍历堆应用进程空间中每个活动线程的堆栈,检查每个线程上的每个堆栈引用变量...

I don't believe there is a way... You would have to either be able to walk the Heap, and examine every object there, or walk the stack of every active thread in the application process space, examining every stack reference variable on every thread...

另一种方式(我猜你做不到)是拦截所有对象创建活动(使用容器方法)并保留应用程序中所有对象的列表......

The other way, (I am guessing you can't do) is intercept all Object creation activities (using a container approach) and keep a list of all objects in your application...

这篇关于如何获取实现给定接口的所有加载类型的所有实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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