title: Looping through classes, and child classes to retrieve properties and values in C#
body: <p>I'm trying to loop through a class and it's child classes to get the values passed with it.</p>
  
  <p>Here's my class:</p>
  
  <pre><code>public class MainClass
  {
      bool IncludeAdvanced { get; set; }
  
      public ChildClass1 ChildClass1 { get; set; }
      public ChildClass2 ChildClass2 { get; set; }
  }
  </code></pre>
  
  <p>Here's my code so far</p>
  
  <pre><code>GetProperties&lt;MainClass&gt;();
  
  private void GetProperties&lt;T&gt;()
  {
      Type classType = typeof(T);
      foreach (PropertyInfo property in classType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
      {
          WriteToLog(property.Name + ": " + property.PropertyType + ": " + property.MemberType);
          GetProperties&lt;property&gt;();
      }
  }
  </code></pre>
  
  <p>Two questions:</p>
  
  <ol>
  <li>What do I pass to GetProperties, to pass the child class, for it to then loop through it's properties if it's a class?</li>
  <li>How do I get the value from the property item if it isn't a class?</li>
  </ol>
  
  <p>Hopefully this all makes sense. If not, don't hesitate to ask and I'll try and clarify.</p>
  
  <p>Thanks</p>