I'm attempting to learn some reflection and so far it's not going very well. 
I'm trying to dynamically view the properties of an object, which is going 
ok. But I have a multi-layered object, where one property might return a new 
object, and within that object a property might return another object etc.

So for example. I have a fully populated "Book" class. It has a property of 
"Author", which returns an "Author" class object. Then the "Author" object 
might have a property which returns another object that has been populated, 
and so on.

I can determine individual properties about the "author" property, but how 
do I actually get a hold on this populated author object so that I can then 
read through its properties, and on and on. And to avoid any confusion, yes 
I could just hard code the names in and set them, but in this example lets 
say I dont know what the object and property names are going to be at build 
time, suppose they're read out of some data/xml file at run-time that 
defines all of my objects.

So I'm off to a sad start. I've only managed to get myself this far:
...
code to read in xml file that defines object(s)
...
*var className = child.Attributes["ClassName"].Value;
PropertyInfo pi = typeof(Book).GetProperty(className);
if (pi.GetValue(Book, null) != null)
.. and various other property values

*In this example I know the name of my main object, "Book" but everything 
from there down is dynamic*.

*

Reply via email to