List all DLL's implementing a specific interface from the GAC

后端 未结 5 1821
借酒劲吻你
借酒劲吻你 2021-01-21 09:49

Aloha

Given a plug-in architecture (C# / .NET 3.5) with the plug-ins stored in the GAC, how can I list/load all dll\'s that contain types that implement my specific inte

5条回答
  •  天涯浪人
    2021-01-21 10:38

    First a little clarification: a DLL cannot implement an interface. The DLL contains types that could implement a specific interface. Here's a .NET wrapper around fusion.dll that allows you to enumerate all the assemblies in the GAC. Once you have loaded the assembly with Assembly.Load you can try to find all the types that implement the specific interface:

    foreach (var type in assembly.GetTypes())
    {
        var myInterfaceType = typeof(IMyInterface);
        if (type != myInterfaceType && myInterfaceType.IsAssignableFrom(type))
        {
            Console.WriteLine("{0} implements IMyInterface", type);
        }
    }
    

提交回复
热议问题