title: Get Values From Complex Class Using Reflection
body: <p>I have a class, which is created and populated from an xml string, I've simplified it for example purposes:</p>
  
  <pre><code>[XmlRoot("Person")]
  public sealed class Person
  {
      [XmlElement("Name")]
      public string Name { get; set; }
  
      [XmlElement("Location")]
      public string Location { get; set; }
  
      [XmlElement("Emails", Type = typeof(PersonEmails)]
      public PersonEmails Emails { get; set; }
  }
  
  public class PersonEmails
  {
      [XmlElement("Email", Type = typeof(PersonEmail))]
      public PersonEmail[] Emails { get; set; }
  }
  
  public class PersonEmail
  {
      [XmlAttribute("Type")]
      public string Type { get; set; }
  
      [XmlText]
      public string Value { get; set; }
  }
  </code></pre>
  
  <p>To extract the information, I'm trying to load them into another class, which is simply:</p>
  
  <pre><code>public class TransferObject
  {
      public string Name { get; set; }
  
      public ObjectField[] Fields { get; set; }
  }
  
  public class ObjectField
  {
      public string Name { get; set; }
      public string Value { get; set; }
  }
  </code></pre>
  
  <p>I'm only populating "Fields" from the other object, which would simply be (Name = "Location", Value = "London"), but for Emails, (Name = "Email"+Type, Value = jeff@here.com)</p>
  
  <p>Currently I can populate all the other fields, but I'm stuck with Emails, and knowing how to dig deep enough to be able to use reflection (or not) to get the information I need.  Currently I'm using:</p>
  
  <pre><code>Person person = Person.FromXmlString(xmlString);
  List&lt;ObjectField&gt; fields = new List&lt;ObjectField&gt;();
  foreach (PropertyInfo pinfo in person.getType().GetProperties()
  {
      fields.Add(new ObjectField { Name = pinfo.Name, Value = pinfo.getValue(person, null).ToString();
  }
  </code></pre>
  
  <p>How can I expand on the above to add all my emails to the list?</p>