title: Combine two LINQ queries?
body: <p>I think I am having a mental block but can someone please enlighten me on how to combine these two LINQ statements into one? </p>
  
  <pre><code>/// &lt;summary&gt;
  /// Returns an array of Types that implement the supplied generic interface in the
  /// current AppDomain.
  /// &lt;/summary&gt;
  /// &lt;param name="interfaceType"&gt;Type of generic interface implemented&lt;/param&gt;
  /// &lt;param name="includeAbstractTypes"&gt;Include Abstract class types in the search&lt;/param&gt;
  /// &lt;param name="includeInterfaceTypes"&gt;Include Interface class types in the search&lt;/param&gt;
  /// &lt;returns&gt;Array of Types that implement the supplied generic interface&lt;/returns&gt;
  /// &lt;remarks&gt;
  /// History.&lt;br/&gt;
  /// 10/12/2008      davide       Method creation.&lt;br/&gt;
  /// &lt;/remarks&gt;
  public static Type[] GetTypesImplementingGenericInterface(Type interfaceType, bool includeAbstractTypes, bool includeInterfaceTypes)
  {
      // Use linq to find types that implement the supplied interface.
      var allTypes = AppDomain.CurrentDomain.GetAssemblies().ToList()
                      .SelectMany(s =&gt; s.GetTypes())
                      .Where(p =&gt; p.IsAbstract == includeAbstractTypes  
                                      &amp;&amp; p.IsInterface == includeInterfaceTypes);
  
      var implementingTypes = from type in allTypes
                              from intf in type.GetInterfaces().ToList()
                              where intf.FullName != null &amp;&amp; intf.FullName.Contains(interfaceType.FullName)
                              select type;
  
      return implementingTypes.ToArray&lt;Type&gt;();
  }
  </code></pre>
  
  <p>I am avoiding IsAssignableFrom as its seems to fail when not supplying the specific type of the generic interface therefore I believe using FullName caparison over IsAssignableFrom should suffice, for example:</p>
  
  <pre><code>namespace Davide
  {
      interface IOutput&lt;TOutputType&gt; { }
  
      class StringOutput : IOutput&lt;string&gt; { }
  }
  </code></pre>
  
  <p>typeof(IOutput&lt;>).FullName will return "Davide+IOutput`1"</p>
  
  <p>typeof(StringOutput).GetInterfaces()[0].FullName will return "Davide+IOutput`1[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"</p>
  
  <p>Therefore using FullName.Contains should suffice</p>