title: Get all classes in project in Visual Studio Scaffolder
body: <p>I am building a scaffolding tool for visual studio, and need to present a list of classes that derive from a certain abstract class, but only classes in the active project. I have it working, but it takes visual studio a little while to run the code.</p>
  
  <pre><code>ICodeTypeService codeTypeService = (ICodeTypeService)Context
                      .ServiceProvider.GetService(typeof(ICodeTypeService));
  
  var types = codeTypeService.GetAllCodeTypes(Context.ActiveProject);
  
  foreach (var type in types)
  {
      type.
      if (type.Kind == vsCMElement.vsCMElementClass)
      {
          foreach (var d in type.Bases)
          {
              var dClass = d as CodeClass;
              var name = type.Name;
              if (dClass.Name == "MyAbstractClass")
              {
                  if (type.Namespace.Name.Contains(Context.ActiveProject.Name))
                  {
                      yield return type.Name;
                  }
              }
  
          }
      }
  }
  </code></pre>
  
  <p>So I'm having to do a check of the namespace when it finds a matching class to make sure it is in my project. This feels like I am doing a hell of a lot of unnecessary work. This is the example they give with the scaffold template visual studio project:</p>
  
  <pre><code>ICodeTypeService codeTypeService = (ICodeTypeService)Context
                      .ServiceProvider.GetService(typeof(ICodeTypeService));
  
  return codeTypeService
      .GetAllCodeTypes(Context.ActiveProject)
      .Where(codeType =&gt; codeType.IsValidWebProjectEntityType())
      .Select(codeType =&gt; new ModelType(codeType));
  </code></pre>
  
  <p>is the codetypeservice the right way to do this?</p>
  
  <p><strong>EDIT</strong>
  Basically when it searches for classes it doesn't just do it in the current active project, but also searches all the referenced projects. This is why I have to check the namespace so I only get the results from the active project. I reckon this is why it is slowed right down because the referenced projects are quite large so it is doing a hell of a lot of completely unnecessary work...</p>