我如何可以扫描位于bin目录中的所有组件和检索所有类型实现接口?
How can I scan all assemblies located in the bin directory and retrieve all types implementing an interface?
您可以找到他们很容易使用反射和LINQ查询
You can find them easily using Reflection and a LINQ query
var type = typeof(IRyuDice);
var types = AppDomain.CurrentDomain.GetAssemblies().ToList()
.SelectMany(a => a.GetTypes())
.Where(t => type.IsAssignableFrom(t));
AppDomain.CurrentDomain.GetAssemblies
返回 System.Reflection.Assembly []
集合。然后,选择在大会所有类型和检查,如果你的接口使用该类型。
AppDomain.CurrentDomain.GetAssemblies
returns a System.Reflection.Assembly[]
collection. Then you select all Types in that Assembly and check if your interface is used by that type.
http://msdn.microsoft.com/en-us/library/system.appdomain.getassemblies.aspx