开发者

How can I get only classes defined in the current project in EnvDTE?

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 Cod开发者_如何学JAVAeClass || 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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜