title: Getting all ICollection properties through reflection
body: <p>I'm trying to fetch all <code>ICollection&lt;T&gt;</code> properties from class of unknown type. Also, type T (what the collection is of) is not known at compile time. Firstly I've tried this approach:</p>
  
  <pre><code>foreach (var property in entity.GetType().GetProperties())
  {
      if (typeof(ICollection).IsAssignableFrom(property.PropertyType) || typeof(ICollection&lt;&gt;).IsAssignableFrom(property.PropertyType))
      {
          // do something
      }
  }
  </code></pre>
  
  <p>but it's not working (evaluating false even for <code>ICollection</code> properties).</p>
  
  <p>I got it working like this:</p>
  
  <pre><code>foreach (var property in entity.GetType().GetProperties())
  {
      var getMethod = property.GetGetMethod();
      var test = getMethod.Invoke(entity, null);
      if (test is ICollection)
      {
          // do something
      }
  }
  </code></pre>
  
  <p>but I do not want to execute all getters. Why is the first piece of code not working? How can I find <code>ICollection</code> properties without executing all getters?</p>