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

StackOverflow https://stackoverflow.com/questions/3560823

  •  01-10-2019
  •  | 
  •  

Pergunta

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.

Foi útil?

Solução

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.

Outras dicas

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top