Reputation: 7197
How can i do this code in one linq statement?
i.e. add the results of all linq statements to one big enumeration
List<Type> alltypes = new List<Type>();
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (var assembly in assemblies)
{
foreach (var type in assembly.GetTypes())
{
alltypes.Add(type);
}
}
Upvotes: 0
Views: 68
Reputation: 1500185
It sounds like you want:
var allTypes = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(assembly => assembly.GetTypes())
.ToList();
Use SelectMany
when one "input" item (an assembly in this case) is used as the source for multiple other items (types in this case).
If you want it in a query expression:
var allTypes = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
from type in assembly.GetTypes()
select type).ToList();
Upvotes: 3