title: Constructing a navigation path between two objects
body: <p>Given two .NET objects (a root and a leaf) in an arbitrary object graph (linked by properties and collections), is there an existing API or example to construct a path (something like a WPF property binding path, or XML XPath) to get from one to the other?  The "source" (ie. the object which wants to find out the path), will be the leaf object.</p>
  
  <p>Indexed locations must also be supported.  (eg. <code>Foo.Bar[42].Baz["frog"].Quux</code>).</p>
  
  <p>This is mainly intended for error reporting -- I would like to let objects log an error showing where they are in the object model, rather than just by their type name.  (This is important because the same type of object might be contained by a large number of other object types, and the user action required to fix any issues will vary depending on that location.)</p>
  
  <p>I can hand-roll something which does the trick by giving each object a reference to its parent and recursively asking each parent how to get to the child.  But before I go do that I was wondering if there were any existing/better solutions.  (And this is fragile if someone forgets to update the parent link, or if one object can be reached by two different paths, although that should be rare.)</p>