title: How do I enumerate all items that implement a generic interface?
body: <p>I have two interfaces, a generic and a non-generic that have an inheritence hierarchy: </p>
  
  <pre><code>public interface IGenericRelation&lt;TParent, TChild&gt; : IRelation
  
  public interface IRelation
  </code></pre>
  
  <p>The generic one is implemented by several server controls that are loaded dynamically and I wish to enumerate on the collection of controls that implement this interface.  I can do the following </p>
  
  <pre><code>    foreach (IRelation relationControl in this.uiPlhControls.Controls.OfType&lt;IRelation)
      { ... }
  </code></pre>
  
  <p>But what I'd really like to be able to do is... </p>
  
  <pre><code>    foreach (IGenericRelation&lt;,&gt; relationControl in this.uiPlhControls.Controls.OfType&lt;IGenericRelation&lt;,&gt;)
      { ... }
  </code></pre>
  
  <p>and then be able to use the <code>relationControl</code> with the types that it supplied as then I'd have access to the strongly-typed properties available on IGenericRelation. Unfortunately this isn't possible as it seems I can't omit the type parameters.</p>
  
  <p>Does anyone know a way to enumerate the controls that implement a generic interface to prevent me having to write several loops instead of one?  Using reflection perhaps?</p>