获取相关的组件? [英] Get dependent assemblies?
本文介绍了获取相关的组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法让依赖于给定程序集中的所有组件?
伪:
组装一= GetAssembly();
VAR家属= a.GetDependants();
解决方案
如果你想找到从当前应用程序域的依赖组件,您可以使用类似的 GetDependentAssemblies
函数定义如下:
私人的IEnumerable<大会> GetDependentAssemblies(大会analyzedAssembly)
{
返回AppDomain.CurrentDomain.GetAssemblies()
。凡(一个=> GetNamesOfAssembliesReferencedBy(一)
。载(analyzedAssembly.FullName));
}
公开的IEnumerable<字符串> GetNamesOfAssembliesReferencedBy(装配组装)
{
返回assembly.GetReferencedAssemblies()
。选择(的AssemblyName => assemblyName.FullName);
}
在 analyzedAssembly
参数重新presents您要查找所有家属的组装。
Is there a way to get all assemblies that depend on a given assembly?
Pseudo:
Assembly a = GetAssembly();
var dependants = a.GetDependants();
解决方案
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);
}
The analyzedAssembly
parameter represents the assembly for which you want to find all the dependents.
这篇关于获取相关的组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文