[Mono-dev] Utilizing the C# Parser

Alexandre Miguel Pedro Gomes alexmipego at gmail.com
Fri Feb 3 07:39:18 EST 2006


The mcs C# parser is optimized to compilation, so it won't give you all the
information you would want, instead it would give you a "pre-compilation"
tree where somethings where already changed to optimize the compilation
etc...

If you whish to get only the namespaces, classes, methods, etc... but
nothing about the code inside the methods, etc... I would suggest you to use
System.Reflection and/or Cecil. From here it seems there will be a problem -
you only have source code and you don't need an assembly - so if you're sure
the source code is compilable you can use CodeDOM to build it on-the-fly and
then apply Reflection to that.

If you need to get information about method/properties code and/or line
numbers/columns for the code, then I would suggest you to look at some of
the parsers avaible out there. Your best bet would be the MonoDevelop
parser. Another try would be to search for some parser generators (cocoa,
grammatica, gold and antlr comes to mind) and do/change an existing C#
grammar - the same applies to the MonoDevelop and mcs parsers where you can
get their grammar and change to make it do whatever you need.

On 2/3/06, Robert Jordan <robertj at gmx.net> wrote:
>
> Hey,
>
> > I want to use the mono C# Parser to get information about class stucture
> > etc. in a project.
>
> You don't need to parse C# for "information about class structure etc."
> if "etc." doesn't contain code metrics and if the source code you
> want to introspect is compilable. It's far easier to use
> System.Reflection for that.
>
> Some code metrics can be obtained from IL as well. Have a look at
>
> http://www.mono-project.com/Gendarme
> http://www.mono-project.com/Cecil
>
> Robert
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>



--
Alexandre Gomes, Portugal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060203/a88c69c2/attachment.html 


More information about the Mono-devel-list mailing list