tags:

views:

14

answers:

1

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.

A: 

Hello,

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.

Regards,

Carlos Quintero

Carlos Quintero