title: Get property of generic class
body: <p>I have a generic class, and an object value where <code>obj.GetType().GetGenericTypeDefinition() == typeof(Foo&lt;&gt;)</code>.</p>
  
  <pre><code>class Foo&lt;T&gt;
  {
      public List&lt;T&gt; Items { get; set; }
  }
  </code></pre>
  
  <p>How do I get the value of <code>Items</code> from <code>obj</code>? Remember, <code>obj</code> is an <code>Object</code>, I can't cast <code>obj</code> as <code>Foo</code> because I don't know what <code>T</code> is.</p>
  
  <p>I was hoping to use reflection for this, but each time I do <code>GetProperty("Items")</code> it returns null. However, if someone knows a good way to do this without reflection, by all means.</p>
  
  <p>Let's say my code looks like this:</p>
  
  <pre><code>//just to demonstrate where this comes from
  Foo&lt;int&gt; fooObject = new Foo&lt;int&gt;();
  fooObject.Items = someList;
  object obj = (object)fooObject;
  
  //now trying to get the Item value back from obj
  //assume I have no idea what &lt;T&gt; is
  PropertyInfo propInfo = obj.GetType().GetProperty("Items"); //this returns null
  object itemValue = propInfo.GetValue(obj, null); //and this breaks because it's null
  </code></pre>