CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2006
    Posts
    199

    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.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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.

  3. #3
    Join Date
    Aug 2008
    Posts
    902

    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.

  4. #4
    Join Date
    Jun 2008
    Posts
    2,477

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured