Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7501637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:36:22+00:00 2026-05-29T20:36:22+00:00

I have an assembly containing types that have a common ancestor class (defined within

  • 0

I have an assembly containing types that have a common ancestor class (defined within the assembly. The common ancestor is in most cases not the class’s immediate base type.

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 myAssembly.GetTypes() and examine the properties of the types themselves. In other words I have to work with classes, not instances of the classes.

How do I examine each Type in this collection to find if it inherits from the desired common ancestor or not?

Later: no worries, I have it now. The trick is to instantiate a type object that is the ancestor type from the assembly, eg

Type ancestor = assy.getType("myAncestorClassName", true, true);
Type[] interestingClasses = assy.GetTYypes().Where(t => t.IsSubclassOf(ancestor));

However this will not work:

Type[] interestingClasses = assy.GetTYypes().Where(t => t.IsSubclassOf(typeof(AncestorClass)));

because, I think, the ancestor type is defined in the other assembly and not in the main assembly.

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).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:36:23+00:00Added an answer on May 29, 2026 at 8:36 pm

    For each type in your collection, you can see if they derive from this ancestor by using Type.IsAssignableFrom.

    For example:

    var types = assembly.GetTypes().Exclude(t => typeof(CommonAncestor).IsAssignableFrom(t));
    

    This should get all types in the assembly which aren’t derived from CommonAncestor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assembly containing a number of classes. This is a class library
When I have class containing a static constructor, is that constructor called when the
In MVC/MVP style applications that have Controller/Presenter classes within the Client Application assembly and
I have 2 assemblies, A containing the Main method and the Foo class, that
I have an assembly containing very thorough XML-based documentation, which is used through Sandcastle
If I have two assemblies, one containing just business rules (assembly A), and the
In brief: Is it ever excusable to have assembly names and class names stored
I have an assembly which should not be used by any application other than
I have an assembly that may be used by more than one process at
I have an assembly that is targeted for .NET 3.5. I have an application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.