title: Pass a type to an extension in c#?
body: <p>In Unity, say you have <code>class Explosion:MonoBehavior</code>, using <code>GetComponent</code> you can trivially</p>
  <pre><code>List&lt;Transform&gt; result = new List&lt;Transform&gt;();
  foreach (Transform t in here)
      {
      if ( t.GetComponent&lt;Explosion&gt;() )
        result.Add( t );
      }
  </code></pre>
  <p>The list now contains any immediate active or inactive children, which have the &quot;Explosion&quot; component.</p>
  <p>I want to make an extension which does that, along the lines</p>
  <pre><code>List&lt;Explosion&gt; = transform.Tricky(typeof(Explosion));
  </code></pre>
  <p>So, the extension would look something like ...</p>
  <pre><code>public static List&lt;Transform&gt; Tricky(this Transform here, Type ttt)
      {
      List&lt;Transform&gt; result = new List&lt;Transform&gt;();
      foreach (Transform t in here)
          {
          if ( t.GetComponent&lt;ttt&gt;() )
              result.Add( t );
          }
      return result;
      }
  </code></pre>
  <p>However I have utterly failed to figure this out. How to?</p>
  <hr />
  <h1>Note!</h1>
  <p>I do know how to do this with generics:</p>
  <pre><code>public static List&lt;T&gt; MoreTricky&lt;T&gt;(this Transform here)
    {
    List&lt;T&gt; result = new List&lt;T&gt;();
    foreach (Transform t in here)
        {
        T item = t.GetComponent&lt;T&gt;(); if (item != null) result.Add(item);
        }
    return result;
    }
  </code></pre>
  <p>(so, <code>List&lt;Dog&gt; d = t.MoreTricky&lt;Dog&gt;();</code>)   Incredibly, I am so lame I don't know how to do it &quot;normally&quot;, passing in the type.</p>