My .Net Adventure

Tag Archives: findall

Often times you need to be able to take action on an entire object graph, or specific types in a graph. An example of this could be walking the graph and setting a single property on all of your business objects. Perhaps a bool indicating the state of an object like IsDirty. Well since graphs are all different shapes a handy way to do this is through c# iterators. The idea being you supply a root object and the type of object you want to deal with. The method will then return to you each instance of said type.

There are a couple of things we want to do with this implementation.

Ensure that it can be short circuited by the caller. After all you may want to use this method to inspect a graph for broken rules. And as soon as you find an InValid instance return and prevent further recursion.

Supply a list of types to ignore in the recursion allowing the caller to limit useless graph traversal.

Should be provided as an extension method so it can be used with all object graphs.