Question: Is there a better (more performant or nicer code ;) way to find all derived Types of a Type?
Currently im using something like:

1. get all types in used Assemblies
2. check my type with all those types if it is 'IsAssignable'

I was wondering if theres a better way todo this?

Answer: 
I [once](https://stackoverflow.com/questions/2689566/how-to-add-xmlinclude-attribute-dynamically/14403538#14403538) used this Linq-method to get all types inheriting from a base type B:

```
    var listOfBs = (
                from domainAssembly in AppDomain.CurrentDomain.GetAssemblies()
                // alternative: from domainAssembly in domainAssembly.GetExportedTypes()
                from type in domainAssembly.GetTypes()
                where typeof(B).IsAssignableFrom(type)
                // alternative: && type != typeof(B)
                // alternative: && ! type.IsAbstract
                // alternative: where type.IsSubclassOf(typeof(B))
                select type).ToArray();

```

**EDIT**: As this still seems to get more rep (thus more views), let me add a fluent version and some more details:

```
   var listOfBs = AppDomain.CurrentDomain.GetAssemblies()
                // alternative: .GetExportedTypes()
                .SelectMany(domainAssembly => domainAssembly.GetTypes())
                .Where(type => typeof(B).IsAssignableFrom(type)
                // alternative: => type.IsSubclassOf(typeof(B))
                // alternative: && type != typeof(B)
                // alternative: && ! type.IsAbstract
                ).ToArray();

```

Details:

* As the above-mentioned link states, this method uses Reflection on each call. So when using the method repeatedly for the same type,
one could probably make it much more efficient by loading it once.
* As [Anton](https://stackoverflow.com/a/857720) suggests, maybe you could (micro)optimize it using `domainAssembly.GetExportedTypes()`
to retrieve only publicly visible types (if that's all you need).
* As [Noldorin](https://stackoverflow.com/a/857728) mentions, `Type.IsAssignable` will also get the original (non-derived) type. (`Type.IsSubclassOf` will not, but `Type.IsSubclassOf` will not work if the base type is an interface). But of course, one can exclude the original base class: `&& type != typeof(B)`.
* One may want/need to check for a concrete implemented class, i.e. ignore abstract classes: `&& ! assemblyType.IsAbstract`. (Note that all interfaces are considered abstract, see [MSDN](https://msdn.microsoft.com/en-us/library/system.type.isabstract%28v=vs.110%29.aspx).)
* FWIW: as Jon Skeet [suggested](https://stackoverflow.com/a/1268416) in a similar question: "it is trickier if you need to handle generics".
A quick search returns some suggestions, but there are probably more, and I did not check them (e.g. for correctness):
	+ [Get all types implementing specific open generic type](https://stackoverflow.com/questions/8645430/get-all-types-implementing-specific-open-generic-type)
	+ [Get all implementations types of a generic interface](https://stackoverflow.com/questions/42245011/get-all-implementations-types-of-a-generic-interface)
	+ [Getting all types that implement an interface](https://stackoverflow.com/questions/26733/getting-all-types-that-implement-an-interface)
Just create a static dictionary of derived types on start and do lookup with that.
Eg. `public static Dictionay<Type, Type[]> DerivedTypes { get;set; }`
where Type is any type you want to include in the search
and Type[] is a list of derived types.
Fill the dictionary up when app starts and use it during the whole life of the app.