Using LINQ you can do this:
var lista = (from arquivo in AppDomain.CurrentDomain.GetAssemblies()
from tipo in arquivo.GetTypes()
where typeof(ClasseBase).IsAssignableFrom(tipo)
select tipo).ToArray();
Behold working in the ideone. And in the .NET Fiddle. Also put on the Github for future reference.
With LINQ using expressions lambda (set up by AP Rod):
var teste = AppDomain.CurrentDomain.GetAssemblies().Select(x => x.GetTypes())
.SelectMany(x => x).Where(x => typeof(ClasseBase).IsAssignableFrom(x))
.ToArray();
Linless:
foreach(var arquivo in AppDomain.CurrentDomain.GetAssemblies()) {
foreach (var tipo in arquivo.GetTypes()) {
if (typeof(ClasseBase).IsAssignableFrom(tipo)) {
Console.WriteLine(tipo);
}
}
}
Behold working in the ideone. And in the .NET Fiddle. Also put on the Github for future reference.
that’s exactly what I wanted, thank you, but I’m trying to adapt without using LINQ, but still, thank you.
– Rod
Do you have Resharper? It helps do this. I haven’t worked with C# for some time so I don’t have all the tools to make the job easier. Of course you can do manual too, it’s not complicated.
– Maniero
my Resharp expired today, but I’ll try to do it manually anyway, thank you
– Rod
Done in the hand real quick.
– Maniero
I also did in lambda, adds in your answer, which is more complete, for those who someday come looking, code: var test = Appdomain.CurrentDomain.Getassemblies() . Select(x => x.Gettypes()) . Selectmany(x => x) . Where(x => typeof(Classebase).Isassignablefrom(x)). Toarray();
– Rod