简体   繁体   中英

Search for interface in all assemblies of bin

如何扫描bin目录中的所有程序集并检索实现接口的所有类型?

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 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

My answer might be too obvious but I'll give it a shot...

You need to take a look at DirectoryInfo to get every file (*.dll) of the directory and the use reflection in order to digg into them...

Does that answer your question or do you want to know the actual implementation?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM