Hi guys and gals.
I am having a problem with reflection, and accessing sub-classes. Let's take a look at this structure:
public class Master {
public int ID { get; set; }
public string Name { get; set; }
public Child FirstChild { get; set; }
}
public class Child {
public int ID { get; set; }
public string Name { get; set; }
}
If I want to get the value of the Name property on the master class I can do this:
string name = item.GetType().GetProperty("Name").GetValue(item, null).ToString();
But If I want to access the value of the Name property of the FirstChild, I am stuck. I have read StackOverflow from cover to cover trying to find out how to do this ... do you have any insights ?
And I know reflection is performance heavy, but it's used in very few cases in our system, but getting this to work would simplify things a great deal.