4

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

ryudice
  • 36,476
  • 32
  • 115
  • 163

2 Answers2

11

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

hunter
  • 62,308
  • 19
  • 113
  • 113
  • 12
    I don't think this answers the question as it will only process assemblies that are LOADED in the CurrentDomain, not those present but as-yet unused in the bin directory. There is an answer here that might help: http://stackoverflow.com/questions/1288288/how-to-load-all-assemblies-from-within-your-bin-directory – Rob Von Nesselrode Nov 11 '13 at 06:02
2

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?

sebagomez
  • 9,501
  • 7
  • 51
  • 89