如何在 EnvDTE 中仅获取当前项目中定义的类?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我用于导航 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.
老问题,但我会将其发布以供将来参考。
当元素来自引用的程序集时,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