gpt4 book ai didi

visual-studio - 从 VS2010 扩展中获取当前解决方案中程序集的类型信息

转载 作者:行者123 更新时间:2023-12-01 11:56:30 25 4
gpt4 key购买 nike

我正在为 VS2010 中的 UML 序列图构建命令扩展,并且需要在当前解决方案中实现特定接口(interface)的类型列表。您如何从扩展中访问类型和程序集信息?到目前为止,我所有的尝试都只是列出了原始扩展项目中加载的程序集,而不是 VS 当前正在编辑的程序集。

最佳答案

这是我最终得出的解决方案,使用 linq 来简化搜索:

DTE dte = (DTE)ServiceProvider.GetService(typeof(DTE));
var types = from Project project in dte.Solution.Projects
from Reference reference in (References)project.Object.References
where reference.Type == prjReferenceType.prjReferenceTypeAssembly
from t in Assembly.LoadFile(reference.Path).GetTypes()
where t != typeof(IInterface) && typeof(IInterface).IsAssignableFrom(t)
select t;

此 block 搜索当前打开的解决方案中包含的所有项目,获取它们的所有引用,加载程序集,并在其中搜索实现接口(interface)的类型。

关于visual-studio - 从 VS2010 扩展中获取当前解决方案中程序集的类型信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6627896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com