3

I'm using the tangible T4 example from the documentation and pull the classes as followed:

// get all class items from the code model
var allClasses = VisualStudioHelper.CodeModel.GetAllCodeElementsOfType(project.CodeModel.CodeElements, EnvDTE.vsCMElement.vsCMElementClass, false);

And the methods:

// get all methods implemented by this class
var allFunctions = VisualStudioHelper.CodeModel.GetAllCodeElementsOfType(codeClass.Members, EnvDTE.vsCMElement.vsCMElementFunction, false);

Here is how I initialize project and codeClass:

var project = VisualStudioHelper.GetProject("CodeBase");
var allClasses = VisualStudioHelper.CodeModel.GetAllCodeElementsOfType(project.CodeModel.CodeElem‌​ents, EnvDTE.vsCMElement.vsCMElementClass, false); 

foreach(CodeClass codeClass in allClasses) { ..... }

This works except that I don't get all methods from the class. The class is a partial class and I only get the methods from the 1st *.cs file.

Any idea or workaround?

  • Please see ["Should questions include “tags” in their titles?"](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles), where the consensus is "no, they should not"! –  Mar 09 '16 at 16:15
  • Very helpful. I still don't know the answer to my question, but at least I got lectured on tags in message headers. – CSharpDummy Mar 10 '16 at 21:27
  • Can you show your code where you initialize `project` and `codeClass`? – Justin R. Mar 11 '16 at 00:05
  • Here is how I initialize project and codeClass: var project = VisualStudioHelper.GetProject("CodeBase"); var allClasses = VisualStudioHelper.CodeModel.GetAllCodeElementsOfType(project.CodeModel.CodeElements, EnvDTE.vsCMElement.vsCMElementClass, false); foreach(CodeClass codeClass in allClasses) { ..... } – CSharpDummy Mar 11 '16 at 02:43
  • @CSharpDummy could you possibly insert the relevant code to the question itself - placing code in comments is somehow cumbersome to read. –  Mar 11 '16 at 14:05
  • I can actually reproduce this very issue: https://gist.github.com/dittodhole/2bdef7fb74d47bd7cac7 - I strongly believe this is a bug. Alternatively you could try iterating the project's items and build your tree based on items ... :/ meh –  Mar 11 '16 at 20:49
  • Ok I'll send them an email. – CSharpDummy Mar 11 '16 at 20:56

0 Answers0