Home All Groups Group Topic Archive Search About

Automated Refactoring w/ CodeDom and VBCodeProvider...

Author
6 Feb 2006 6:07 AM
jack
Trying to make a utility that

- Reads a VB.Net source file
- Parses it into it's constuent parts
- Evaluates and modifies as required
- Saves the source

I thought that the CodeDom and the VBCodeProvider would be the way to
go.

I can gen code and compile it, but I can not figure out how to parse a
VB.Net file into a CodeCompileUnit. (Neither CreateParser or Parse
seems to work)

How to I read a VB.Net source file into theee code dom so that I can
progaramatically inspect it.

Am I going down the wrong path?

Jack Stephenson

Author
6 Feb 2006 7:31 AM
Oleg Zherebin
Look #d sources. It has some refactoring support.

Show quoteHide quote
"jack" <jack.stephen***@lycos.com> wrote in message
news:1139206053.926180.31980@z14g2000cwz.googlegroups.com...
> Trying to make a utility that
>
> - Reads a VB.Net source file
> - Parses it into it's constuent parts
> - Evaluates and modifies as required
> - Saves the source
>
> I thought that the CodeDom and the VBCodeProvider would be the way to
> go.
>
> I can gen code and compile it, but I can not figure out how to parse a
> VB.Net file into a CodeCompileUnit. (Neither CreateParser or Parse
> seems to work)
>
> How to I read a VB.Net source file into theee code dom so that I can
> progaramatically inspect it.
>
> Am I going down the wrong path?
>
> Jack Stephenson
>
Author
7 Feb 2006 10:08 AM
Carlos J. Quintero [VB MVP]
Hi Jack,

I'm not sure about the CodeDom and VBCodeProvider, but using the
extensibility model of Visual Studio you can create either:

- A macro
- An add-in
- A Visual Studio package (VSIP / VS 2005 SDK).

The extensibility model offers ProjectItem.FileCodeModel, which in turn
offers FileCodeModel.CodeElements, etc. See for example my article:

HOWTO: Navigate the code elements of a file from a Visual Studio .NET macro
or add-in
http://www.mztools.com/articles/2006/MZ008.htm

You have lots of resources to get you started on my web site ("For add-in
developers").

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com


Show quoteHide quote
"jack" <jack.stephen***@lycos.com> escribió en el mensaje
news:1139206053.926180.31980@z14g2000cwz.googlegroups.com...
> Trying to make a utility that
>
> - Reads a VB.Net source file
> - Parses it into it's constuent parts
> - Evaluates and modifies as required
> - Saves the source
>
> I thought that the CodeDom and the VBCodeProvider would be the way to
> go.
>
> I can gen code and compile it, but I can not figure out how to parse a
> VB.Net file into a CodeCompileUnit. (Neither CreateParser or Parse
> seems to work)
>
> How to I read a VB.Net source file into theee code dom so that I can
> progaramatically inspect it.
>
> Am I going down the wrong path?
>
> Jack Stephenson
>
Author
17 Feb 2006 4:52 PM
Stuart Carnie
jack wrote:
Show quoteHide quote
> Trying to make a utility that
>
> - Reads a VB.Net source file
> - Parses it into it's constuent parts
> - Evaluates and modifies as required
> - Saves the source
>
> I thought that the CodeDom and the VBCodeProvider would be the way to
> go.
>
> I can gen code and compile it, but I can not figure out how to parse a
> VB.Net file into a CodeCompileUnit. (Neither CreateParser or Parse
> seems to work)
>
> How to I read a VB.Net source file into theee code dom so that I can
> progaramatically inspect it.
>
> Am I going down the wrong path?
>
> Jack Stephenson
>

There is currently no VB.NET or C# code parser => CodeCompileUnit
function in the BCL.  You would have to write your own CodeParser -
which I've considered myself :)