title: Retrieving a collection from a generic method with a run time generic type
body: <p>I have a generic method </p>
  
  <pre><code>var propertyResolverMethod = _propertyResolver
      .GetType()
      .GetMethod(
          nameof(_propertyResolver.GetEntities),
          new[] { typeof(string), typeof(string) })
      ?.MakeGenericMethod(_itemType);
  </code></pre>
  
  <p>and  the invocation </p>
  
  <pre><code>var recommendedItems = propertyResolverMethod
      ?.Invoke(
          _propertyResolver,
          new object[] { itemId, ResolvedCollectionId });
  </code></pre>
  
  <p>It on the compile-time it returns an object, but on runtime, it returns <code>IQueryable&lt;Item&gt;</code> this item is the item from _itemType and we find out its type only on runtime, but I know that it has a collection inside Item.RelatedItems that I need to get. Tried already casting to dynamic, but does not work for my case, I know that's somehow solvable via Expressions.</p>
  
  <p>Should be iteratable like this </p>
  
  <pre><code>var itemIds = recommendedItems?.Select(i =&gt; i.RelatedItems.Select(s =&gt; s.ItemID));
  </code></pre>
  
  <p>But it's not possible without a proper cast</p>