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

标签 visual-studio visual-studio-2010 vsx envdte

我正在为 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/

相关文章:

visual-studio - Visual Studio 2012 UI 错误修复?

C#:以干净的方式将调试器附加到进程

c# - .Net 核心依赖 - Bower

sdk - 如何为 *.vsct 文件中的工具栏定义 SplitDropDown 或 MenuButton?

c# - 如何从 VSPackage 获取当前运行的 Visual Studio 安装路径

c# - 重命名当前项目的所有命名空间

c# - 每当我将 UserControl 添加到窗体时,我的 UserControl 都会使 Visual Studio 崩溃

asp.net - 如何在 Visual Studio 2010 中打开 IntelliSense?

c# - 循环遍历 DataGridView 单元格

visual-studio - Visual Studio 远程调试可扩展性