获取依赖程序集? [英] Get dependent assemblies?

查看:28
本文介绍了获取依赖程序集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法获取依赖于给定程序集的所有程序集?

Is there a way to get all assemblies that depend on a given assembly?

伪:

Assembly a = GetAssembly();
var dependants = a.GetDependants();

推荐答案

如果您希望从当前应用程序域中查找依赖程序集,您可以使用如下定义的 GetDependentAssemblies 函数:

If you wish to find the dependent assemblies from the current application domain, you could use something like the GetDependentAssemblies function defined below:

private IEnumerable<Assembly> GetDependentAssemblies(Assembly analyzedAssembly)
{
    return AppDomain.CurrentDomain.GetAssemblies()
        .Where(a => GetNamesOfAssembliesReferencedBy(a)
                            .Contains(analyzedAssembly.FullName));
}

public IEnumerable<string> GetNamesOfAssembliesReferencedBy(Assembly assembly)
{
    return assembly.GetReferencedAssemblies()
        .Select(assemblyName => assemblyName.FullName);
}

analyzedAssembly 参数表示要为其查找所有依赖项的程序集.

The analyzedAssembly parameter represents the assembly for which you want to find all the dependents.

这篇关于获取依赖程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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