Using XPath-style query with reflection

I have a class tree that contains several objects in a hierarchy. Therefore, I can have a Container object that hosts 3 SubContainer objects, which, in turn, place an arbitrary number of Item objects.

Is there a way I can use an XPath style expression over this tree of objects, which would imply a reflection so that I can request a class property with an XPath type expression so that the code looks something like:

object o = Container.Query("/Container/SubContainer[1]/Item[1]/@ItemProperty");

The XPath syntax is obviously fully compiled and probably invalid, but it just illustrates to give you an idea of ​​what I'm looking for.

Edit -> The reason I would like to query in this way is that the path to the object is not fixed and therefore must be configured by the application user.

Thanks.

+5
source share
2 answers

I had the same problem, so I wrote a simple extension view for querying objects using reflection

http://code.google.com/p/antix-software/wiki/AntixReflectionQuery

If he doesn’t do exactly what you need, he will at least be the beginning

+4
source

You can write an extension method for a control that takes a string in the description.

.

0

All Articles