Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search for interface in all assemblies of bin

Tags:

c#

.net

asp.net

How can I scan all assemblies located in the bin directory and retrieve all types implementing an interface?

like image 604
ryudice Avatar asked Dec 13 '22 19:12

ryudice


2 Answers

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

like image 185
hunter Avatar answered Dec 15 '22 07:12

hunter


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?

like image 39
sebagomez Avatar answered Dec 15 '22 08:12

sebagomez