Auto-discovery of .DLLs that contain a member function?
I have a project where I have a main assembly and a bunch of support sub-assemblies. Each sub-assembly has exactly the same member functions (each is designed to work with a different data source).
I would like my main assembly to be able to "discover" the sub-assemblies that are included in the program install folder.
So, for instance, if I have 4 sub-assembly .DLLs (say "sub1.dll", "sub2.dll", "sub3.dll", "sub4.dll") that each have a function I could search for (such as "do_something()" I would like to be able to have the main assembly discover them and return maybe a List<> of the assembly names.
Is this possible?
The reason is I frequently add new sub-assemblies but don't want to have to hard-code their names into the main assembly.
Re: Auto-discovery of .DLLs that contain a member function?
Use DirectoryInfo.GetFiles( ) to get a list of the assemblies.
For each assembly you find, call Assembly.Load( ).
Once you have the assembly, call GetTypes( ) to get the class types.
For each type call, GetMethods( ) to retrieve the methods of the class.
See msdn for examples of each of the method calls listed above.
Re: Auto-discovery of .DLLs that contain a member function?
Sounds like a plugin architecture. You might just search Google for that, and specify C# for more tips.
Re: Auto-discovery of .DLLs that contain a member function?
Right, and along those lines you should define a common interface for your types so you don't have to use reflection to check if a method exists or not.