1

How can I access the currently opened project's types(classes) from a Visual Studio add-in(be able to create instances of those classes within the add-in)? Is this possible through reflection? Or maybe dynamically include the project's assembly as a reference?

What I'd like to have in the end is a list of all types accessible from the project, taking into account referenced assemblies and types declared in the project itself. In absence of a method to actually find Type instances, a list of type names may do - this way, I won't run into problems if the project is not yet built and the types therein are not yet implemented.

I use Visual Studio 2008 and the language I prefer is C#.

Edit: I imagine I could parse each file and seek out class declarations, but I'd like to consider types from referenced assemblies as well. The references may be sought after by searching for "using" statements, but that leaves dynamically imported dll types an open issue. Thus, given the branching of separate situations to consider, I'm wondering if there isn't an easier way.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
luvieere
  • 37,065
  • 18
  • 127
  • 179
  • This doesn't sound good. A project is a collection of source code files. There is no concrete implementation of a type until the project is compiled without errors. – Hans Passant Feb 13 '10 at 20:38
  • I assume I already have a compiled and existing assembly generated from the project. As not to rely on it before it actually exists, might there be a way to search if it does? – luvieere Feb 13 '10 at 20:59

2 Answers2

1

Sure, just get the assembly from the output directory and load it. I am not working on any EnvDTE projects right now so I can't just pop in and knock out a sample, but that is how you would be able to enumerate/instantiate classes.

But.... nobugz is hinting that something smells.. What are you trying to do? There may be a 'better' way to do it.

Sky Sanders
  • 36,396
  • 8
  • 69
  • 90
0

The Visual Studio code model offers automation clients the ability to discover code definitions in a project and modify those code elements.

For more information go to:

http://msdn.microsoft.com/en-us/library/ms228763(VS.80).aspx

Mosty Mostacho
  • 42,742
  • 16
  • 96
  • 123
BALKANGraph
  • 2,031
  • 1
  • 15
  • 16