Extending source files by parsing them

R

Rickard

I am trying to write a tool that takes a VB.NET source file containing a
class and produces another source file that contains code that depends
on some properties of the first file.

For example, the original file might contain:
Public Class MyClass
Public Sub MySub
' blah
End Sub
End Class

Then I want to produce a second source file that might contain:
Public Class MyGeneratedClass
Public Sub DoWhateverOnMyClass(arg as MyClass)
End Sub
End Class

Of course this example is very simplified. In reality I want to do a lot
of processing on the first class.

What I want is something like CodeDom for the first class, but VB.NET
has no CodeDom parser. I tried using
CodeProvider.CompileAssemblyFromFile, but this requires me to compile a
complex set of assemblies (and parsing VS project files, which might or
might not be easy depending on the VS API, I have not looked into this).

The problem is, I want only the basic parsing to be done, I don't need
an executable assembly.

Is there some way that lets me go through the VB.NET code without
requiring a full compile of the project? (And of course, short of
writing my own VB parser which is probably a little overkill...)

Is there some way of intercepting the compilation process before it
fails with "Type <whatever> is not defined", or in any way access the
work it did so far?

I am thankful for all input on this subject.

Regards
/ Rickard
 
D

Dmytro Lapshyn [MVP]

Hi Rickard,

There's no VB .NET parser available in .NET Framework. You can try 3rd party
products such as GoldParser (it's free AFAIR).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top