.Net:是否有可能获得由类类型创建的对象实例? [英] .Net: Is it possible to get object instances created earlier by class type?

查看:89
本文介绍了.Net:是否有可能获得由类类型创建的对象实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在.net中获得在应用程序中创建的所有具体类型的实例?我猜这样的信息存储在GC中,但它可以从代码访问?

Is it possible in .net to get all instances of concrete type created in application? I guess such information is stored in GC, but is it accessible from code?

推荐答案

查看Raymond Chen的博客,了解为什么这是一个糟糕的主意(调试除外)。
http://blogs.msdn.com /b/oldnewthing/archive/2010/08/12/10049155.aspx

Check Raymond Chen's blog about why that's a bad idea(except for debugging). http://blogs.msdn.com/b/oldnewthing/archive/2010/08/12/10049155.aspx

要实现它,您需要遍历所有对象,因为CLR不太可能按照类型跟踪对象,所以它会很慢。

And to implement it you'd need to walk all objects on the heap since it's unlikely that the CLR keeps track of the object by type, so it would be very slow.

这篇关于.Net:是否有可能获得由类类型创建的对象实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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