title: How to determine the type of objects in a collection in C#
body: <p>I am attempting to use Reflection in C# to determine at runtime the type of objects in a collection property.  These objects are entities generated by the Entity Framework:</p>
  
  <pre><code>Type t = entity.GetType();
  PropertyInfo [] propInfo = t.GetProperties();
  foreach(PropertyInfo pi in propInfo)
  {
      if (pi.PropertyType.IsGenericType)
      {
          if (pi.PropertyType.GetGenericTypeDefinition() 
              == typeof(EntityCollection&lt;&gt;))   
          //  'ToString().Contains("EntityCollection"))'  removed d2 TimWi's advice
          //
          //  ---&gt;  this is where I need to get the underlying type
          //  ---&gt;  of the objects in the collection :-)
          // etc.
      }
  }
  </code></pre>
  
  <p>How do I identify the type of objects held by the collection?</p>
  
  <p>EDIT:  updated code above, adding first .IsGenericType query to make it work</p>