views:

50

answers:

2

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.

+1  A: 

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
A: 

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

Thank you Muse VSExtensions

Muse VSExtensions