如何从 Visual Studio 加载项访问当前打开的项目类型(类)?

发布于 2024-08-21 14:45:16 字数 379 浏览 6 评论 0原文

如何从 Visual Studio 加载项访问当前打开的项目的类型(类)(能够在加载项中创建这些类的实例)?通过反思这可能吗?或者也许动态地包含项目的程序集作为参考?

我最终想要的是从项目访问的所有类型的列表,考虑到项目本身中声明的引用程序集和类型。如果没有实际查找 Type 实例的方法,则可以使用类型名称列表 - 这样,如果项目尚未构建并且其中的类型尚未实现,我就不会遇到问题。

我使用 Visual Studio 2008,我更喜欢的语言是 C#。

编辑:我想我可以解析每个文件并查找类声明,但我也想考虑引用程序集中的类型。可以通过搜索“using”语句来寻找参考,但这使得动态导入的 dll 类型成为一个悬而未决的问题。因此,考虑到需要考虑的不同情况的分支,我想知道是否没有更简单的方法。

How can I access the currently opened project's types(classes) from a Visual Studio add-in(be able to create instances of those classes within the add-in)? Is this possible through reflection? Or maybe dynamically include the project's assembly as a reference?

What I'd like to have in the end is a list of all types accessible from the project, taking into account referenced assemblies and types declared in the project itself. In absence of a method to actually find Type instances, a list of type names may do - this way, I won't run into problems if the project is not yet built and the types therein are not yet implemented.

I use Visual Studio 2008 and the language I prefer is C#.

Edit: I imagine I could parse each file and seek out class declarations, but I'd like to consider types from referenced assemblies as well. The references may be sought after by searching for "using" statements, but that leaves dynamically imported dll types an open issue. Thus, given the branching of separate situations to consider, I'm wondering if there isn't an easier way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼睛会笑 2024-08-28 14:45:16

当然,只需从输出目录获取程序集并加载它即可。我现在没有从事任何 EnvDTE 项目,因此我不能直接插入并删除示例,但这就是您能够枚举/实例化类的方式。

但是.... nobugz 暗示有什么味道.. 你想做什么?可能有一种“更好”的方法来做到这一点。

Sure, just get the assembly from the output directory and load it. I am not working on any EnvDTE projects right now so I can't just pop in and knock out a sample, but that is how you would be able to enumerate/instantiate classes.

But.... nobugz is hinting that something smells.. What are you trying to do? There may be a 'better' way to do it.

坚持沉默 2024-08-28 14:45:16

Visual Studio 代码模型使自动化客户端能够发现项目中的代码定义并修改这些代码元素。

有关详细信息,请访问:

http://msdn.microsoft .com/en-us/library/ms228763(VS.80).aspx

The Visual Studio code model offers automation clients the ability to discover code definitions in a project and modify those code elements.

For more information go to:

http://msdn.microsoft.com/en-us/library/ms228763(VS.80).aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文