title: Print object's List<> property value C#
body: <p>I have an object type of e.g.:</p>
  
  <pre><code>Class
  {
    public string Variable {get; set;}
    public List&lt;AnotherClass&gt; ListVariable {get; set;}
  }
  
  AnotherClass
  {
    public string Variable {get; set;}
    public int IntVariable {get; set;}
  }
  </code></pre>
  
  <p>I've tried several solutions (<code>ObjectDumper</code>, <code>object.GetProperties</code>) to print all the <code>Class</code> object values to screen;
  The problem concludes in inability to print <code>List&lt;AnotherClass&gt;</code>. Instead of all it's items I get only it's count property.</p>
  
  <p>Tried solutions:</p>
  
  <p><a href="https://stackoverflow.com/questions/6196413/how-to-recursively-print-the-values-of-an-objects-properties-using-reflection">How to recursively print the values of an object&#39;s properties using reflection</a></p>
  
  <p><a href="https://stackoverflow.com/questions/4220991/recursively-get-properties-child-properties-of-an-object">Recursively Get Properties &amp; Child Properties Of An Object</a></p>
  
  <p><a href="https://stackoverflow.com/questions/5958803/finding-all-properties-and-subproperties-of-an-object">Finding all properties and subproperties of an object</a></p>
  
  <p>and several more..</p>
  
  <p>EDIT:</p>
  
  <p>Ok, as I see, I probably didn't describe the problem well.
  I need to print all the object's properties and their values, <strong>when I don't know type of the object and it's properties.</strong> The listed solutions work fine, if object contains only simple properties. The problem shows up if one of the properties is List&lt;></p>
  
  <p><strong>I tried the following:</strong></p>
  
  <p>1) </p>
  
  <pre><code>private static void PrintObject(Object dataSource)
  {
     foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(dataSource))
     {
        string name = descriptor.Name;
        object value = descriptor.GetValue(dataSource);
  
        RichTextBox.Text += name + ": " + value + "\n";
  
        PrintObject(control, value);
     }
  }
  </code></pre>
  
  <p><strong>Gives me the output:</strong></p>
  
  <blockquote>
    <p>CheckStatus: Performed</p>
    
    <p>TextData: System.Collections.Generic.List`1[TextDataField]</p>
    
    <p>Capacity: 16</p>
    
    <p>Count: 15</p>
  </blockquote>
  
  <p>but I was expecting all 15 item values here, not just list count.</p>
  
  <p>2)</p>
  
  <pre><code>RichTextBox.Text = dataSource.DumpToString(); 
  </code></pre>
  
  <p>from <a href="http://objectdumper.codeplex.com/" rel="nofollow noreferrer">http://objectdumper.codeplex.com/</a></p>
  
  <p><strong>Gives pretty much the same output.</strong></p>