简体   繁体   English

在对象图中查找特定类型的对象

[英]Find objects of a specific type in an object graph

Given an object instance, how can I recurse its members (ie the whole object graph) for an object of a specific type, or one that inherits from a specific type? 给定一个对象实例,我该如何为特定类型的对象或从特定类型继承的对象递归其成员(即整个对象图)?

For example, I want to find all objects in session that may have deep indirect references to System.Web.UI.Control. 例如,我想在会话中查找所有可能对System.Web.UI.Control进行深度间接引用的对象。

Don't know exactly how to do it but i'm quite sure you have to use Reflection to iterate over all properties of an object. 不确切地知道该怎么做,但是我很确定您必须使用Reflection来迭代对象的所有属性。 Google and you will most likely find an example. Google,您很可能会找到一个例子。 Like this one http://wiki.asp.net/page.aspx/474/how-to-iterate-through-all-properties-of-a-class/ 像这样的http://wiki.asp.net/page.aspx/474/how-to-iterate-through-all-properties-of-a-class/

With that you can probably figure out how to do the recursion yourself. 这样,您可能可以自己弄清楚如何进行递归。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM