Is it possible to replace method ForEach() usage with Select() or something else to write next code in one string with nested extension methods? OR maybe there are another ways to improve the algorithm?
var list = new List<IStatementParser>();
System.IO.Directory.GetFiles(path, "*.dll")
.ForEach(f => System.Reflection.Assembly.LoadFrom(f)
.GetTypes()
.Where(t => !t.IsInterface && typeof(IFoo).IsAssignableFrom(t))
.ForEach(t => list.Add((IFoo)Activator.CreateInstance(t))));
return list.ToDictionary(k => k.Name, v => v.GetType());
It loads all classes from assemblies in path that implements IFoo and adds them to Dictionary<string, Type> where string is IFoo.Name