I want to get all Types from Solution who inherit specify class. My Solution structure looks like:
AssemblyTest (Solution)
|
- ProjectOne (Class Library)
- - BaseClass.cs (Class)
|
- ProjectTwo (Class Library)
- - FirstExampleClass.cs (Class inherit from BaseClass )
|
- ConsoleApp (Console Application)
- - SecondExampleClass.cs (Class inherit from BaseClass )
- - Program.cs (Class inherit from BaseClass )
In Program.cs
I want to get all Types who inherit BaseClass
. For this, i use code:
var typesList = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(p => p.GetTypes()
.Where(t => typeof(BaseClass)
.IsAssignableFrom(t) && !t.IsAbstract && t.IsPublic && t != typeof(BaseClass)));
But in typesList
i get only one element -> SecondExampleClass
from this same Project where exist Program.cs
.
BaseClass.cs
public class BaseClass{}
FirstExampleClass.cs
public class FirstExampleClass : BaseClass{}
SecondExampleClass.cs
public class SecondExampleClass: BaseClass{}
P.S. ConsoleApp
project has reference to ProjectTwo
reference