如何在 EnvDTE 中仅获取当前项目中定义的类?

发布于 2024-09-16 07:24:17 字数 644 浏览 1 评论 0原文

我有一个 Vs2010 包,当前遵循

EnvDTE=>Solution=>Projects=>CodeModel=>CodeElements

递归执行以下操作并查找类

var q = elements.Cast<CodeElement>()
            .Where(x => x is CodeClass || x is CodeNamespace)
            .Where(x => x.Name.StartsWith("System") == false)
            .Where(x=>x.Name.StartsWith("Infragistics")==false)
            .Where(x=>x.Name.StartsWith("Microsoft")==false)
            .Where(x => x.Name.StartsWith("ICSharpCode")==false);

它运行速度相当慢,有没有办法将此查询/搜索限制为仅在当前项目中定义的类/类型?

据我了解,FileCodeModel既无用也不合适,因为这需要打开每个项目项。

I've got a Package for Vs2010 that currently follows

EnvDTE=>Solution=>Projects=>CodeModel=>CodeElements

to do the following recursively and find classes

var q = elements.Cast<CodeElement>()
            .Where(x => x is CodeClass || x is CodeNamespace)
            .Where(x => x.Name.StartsWith("System") == false)
            .Where(x=>x.Name.StartsWith("Infragistics")==false)
            .Where(x=>x.Name.StartsWith("Microsoft")==false)
            .Where(x => x.Name.StartsWith("ICSharpCode")==false);

It runs fairly slowly, is there a way to restrict this query/search to only classes/types defined within the current project?

As I understand it FileCodeModel is neither useful nor appropriate since that would require opening every project Item.

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

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

发布评论

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

评论(2

岁月打碎记忆 2024-09-23 07:24:17

我用于导航 Project.CodeModel 或 ProjectItem.FileCodeModel 的代码元素的方法在文章中进行了描述:

HOWTO:从 Visual Studio .NET 宏或加载项导航文件的代码元素
http://www.mztools.com/articles/2006/MZ2006008.aspx

如果性能是一个问题,请尝试避免 LINQ 层是否可以提高性能。除此之外,没有什么可做的,因为 EnvDTE 返回的 CodeElements 集合返回所有代码元素,并且在您过滤之后。

The way that I use to navigate the code elements of a Project.CodeModel or ProjectItem.FileCodeModel is described in the article:

HOWTO: Navigate the code elements of a file from a Visual Studio .NET macro or add-in
http://www.mztools.com/articles/2006/MZ2006008.aspx

If performance is an issue, try if avoiding the LINQ layer enhances the performance. Other than that there is no much to do since the CodeElements collections returned by EnvDTE return all the code elements and it is afterwards when you filter.

月下凄凉 2024-09-23 07:24:17

老问题,但我会将其发布以供将来参考。

当元素来自引用的程序集时,CodeElement 类上有一个 InfoLocation 属性,该属性等于 vsCMInfoLocation.vsCMInfoLocationExternal。

欲了解更多信息:
http://msdn.microsoft.com/en-us/library /envdte.codeelement.infolocation.aspx

Old question, but I will post this for future reference.

There is a InfoLocation property on the CodeElement class that is equal to vsCMInfoLocation.vsCMInfoLocationExternal when an element is coming from a referenced assembly.

For more information:
http://msdn.microsoft.com/en-us/library/envdte.codeelement.infolocation.aspx

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