列出所有从GAC实现特定接口的DLL [英] List all DLL's implementing a specific interface from the GAC

查看:95
本文介绍了列出所有从GAC实现特定接口的DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定具有存储在GAC中的插件的插件体系结构(C#/.NET 3.5),我如何列出/加载包含实现我的特定接口的类型的所有dll?换句话说,我想通过查看GAC来研究在计算机上安装了我的应用程序的哪些插件.

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 interface? In other words, I'd like to investigate which plug-ins for my application are installed on a machine, by looking in the GAC.

-Edoode

推荐答案

首先要澄清一点:DLL无法实现接口. DLL包含可以实现特定接口的类型.这是围绕Fusion.dll的 .NET包装器,它允许您枚举所有GAC中的程序集.使用 Assembly.Load 加载程序集之后,您可以尝试找到实现特定接口的所有类型:

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);
    }
}

这篇关于列出所有从GAC实现特定接口的DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆