views:

66

answers:

1

Hi

For my new application I would like to parse another C, C++ or C# project, so that i can later display the graphical representation of all the classes in this project.

So I thought that its a good approach to use a database with the following tables to store the necessary information:

TablePackages:
id | name | parentID

TableClasses:
id | name | packageID | sourceCodeID

TableSourceCode:
id | members | constructors | methods | classID

But now, how can I parse in my C# application the source files of other projects? Are there any libraries available or where should I start?

Should I even rethink my approach and choose a completely different one?

+1  A: 

For C#, you can compile it and use reflection to get the list of all classes/properties/methods. For C/C++, you would perhaps need to implement a parser in some form yourself.

Vlad
Thanks that looks nice. But how can I use reflection on source code that isn't included in my project put is located somewhere on the hard disk?
Roflcoptr
You can [load the assembly](http://msdn.microsoft.com/en-us/library/system.reflection.assembly.load.aspx) and [list the types](http://msdn.microsoft.com/en-us/library/system.reflection.assembly.gettypes.aspx) in it. You would need to [compile](http://support.microsoft.com/kb/304655) your source code, in order to get the assembly.
Vlad
Thanks I'll try it.
Roflcoptr
I works fine, but one little issues is still open. Is there a similar to the Java method getDeclaredMethods()? This lists only the methods thatare declared in this class. GetTypes in c# lists all methods, even those that are inherited. I tried to use getExportedMethods but this lists only the public methods, but not the protected or private or package private ones.
Roflcoptr
Having a type, you can use [`GetMethods`](http://msdn.microsoft.com/en-us/library/16z89wsw.aspx) to list both public and protected/internal/private methods. See [`Type` documentation](http://msdn.microsoft.com/en-us/library/system.type.aspx) for what you can get having a type object. (I must confess that I don't know what does `getExportedMethods` in Java do.)
Vlad