title: Using .net reflection to find a common ancestor class
body: <p>I have an assembly containing types that have a common ancestor class (defined within the assembly. The common ancestor is in most cases <em>not</em> the class's immediate base type.</p>
  
  <p>I need to be able to filter out, from all the types in this assembly, those with this common ancestor. For various reasons I can't instantiate the types (they do not as a rule have a common constructor signature) so I have to start with <code>myAssembly.GetTypes()</code> and examine the properties of the types themselves. In other words I have to work with classes, not instances of the classes.</p>
  
  <p>How do I examine each Type in this collection to find if it inherits from the desired common ancestor or not?</p>
  
  <p>Later: no worries, I have it now. The trick is to instantiate a type object that is the ancestor type <em>from the assembly</em>, eg</p>
  
  <pre><code>Type ancestor = assy.getType("myAncestorClassName", true, true);
  Type[] interestingClasses = assy.GetTYypes().Where(t =&gt; t.IsSubclassOf(ancestor));
  </code></pre>
  
  <p>However this will not work:</p>
  
  <pre><code>Type[] interestingClasses = assy.GetTYypes().Where(t =&gt; t.IsSubclassOf(typeof(AncestorClass)));
  </code></pre>
  
  <p>because, I think, the ancestor type is defined in the other assembly and not in the main assembly.</p>
  
  <p>Much, much later....Thanks to everyone who contributed answers to this. I was diverted to something else along the way, but I now have a neat solution (and have learned something new). </p>