Find objects of a specific type in an object graph
Given an object instance, how can I recurse its members (i.e. the whole object graph) for an object of a specific type, or one that inherits from a specific type?
For e开发者_开发百科xample, I want to find all objects in session that may have deep indirect references to 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. Google and you will most likely find an example. Like this one 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.
精彩评论