views:

98

answers:

2

Hi there.

I want to write my first Visual Studio 2010 add-in. My aim is to create an add-in that helps to automatically generate code for things like:

  • implement superclass constructors
  • create delegation methods for composed object
  • etc.

Of course, in order to know what to generate, my add-in must have a knowledge of the code-file the user is going to insert generated code into. (classes, base-classes ...)

My first thought was to use a C#-parser. Is this the right way to go? Isn't there any .NET-Framework part, COM-Object or whatever "built-in"?

Thank you in advance.

P.S: Is noticed that CSharpCodeProvider's class Parse() method has not been implemented by Microsoft yet. -_-

+1  A: 

You could start by looking at EnvDTE, which will help you browse through project files and code trees already parsed and analyzed by Visual Studio, as well as modifying them. EnvDTE is pretty basic and error-prone (for the few times I used it). Finding good in-depth tutorials is also difficult.

If you're trying to implement such features yourself, good luck, it's definitely doable but the learning curve might be quite steep. Otherwise, you could have a look at ReSharper which already implements the features you're trying to code (and much more). Plus it also has a very well designed API compared to EnvDTE (although not very well documented), allowing to use its internal C# parser / analyzer.

Julien Lebosquain
+1 for EnvDTE. I knew that ReSharper implemented this features. I want to implement this only for learning purposes. :)
Simon
Btw, I started to implement a few features today and it seems to be quite straightforward. Thank you :)
Simon
+2  A: 

You can get a lot of info from the MS Visual Studio Extensibility site. This post from the Visual Studio blog may also get you started with dealing with the in memory code file.

slugster
+1 for visual studio blog. Really useful.
Simon