title: How to recursively print the values of an object's properties using reflection
body: <p>To aid in debugging some code I'm working on, I started to write a method to recursively print out the names and values of an object's properties. However, most of the objects contain nested types and I'd like to print their names and values too, but only on the types I have defined. </p>
  
  <p>Here's an outline of what I have so far:</p>
  
  <pre><code>public void PrintProperties(object obj)
  {
      if (obj == null)
          return;
  
      Propertyinfo[] properties = obj.GetType().GetProperties();
  
      foreach (PropertyInfo property in properties)
      {
          if ([property is a type I have defined])
          {
              PrintProperties([instance of property's type]);
          }
          else
          {
              Console.WriteLine("{0}: {1}", property.Name, property.GetValue(obj, null));
          }
      }
  </code></pre>
  
  <p>The parts between the braces are where I'm unsure.</p>
  
  <p>Any help will be greatly appreciated.</p>