This is a mirror of official site: http://jasper-net.blogspot.com/

Hacking the Mono C# Compiler.

| Sunday, October 10, 2010
Important Update

The original article describes how to grab the parse tree of C# code produced by the mono C# compiler. Unfortunately, the mono C# compiler code IS TOO HARD TO USE. Fortunately, another project CSharpDevelop (http://www.icsharpcode.net/OpenSource/SD/Default.aspx) provides a much better solution to parsing C#. The project I tried is located in "SharpDevelop_4.0.0.6721_Beta3_Source\src\Libraries\NRefactory\NRefactory.sln"

Simply remove a file called GlobalAssembyInfo.cs and compile the solution.  Set NRefactoryDemo project as the start up project. See screenshot. More work is required on my part to compare the CSharpDevelop Solution and the Mono Solution.

What is the C# Mono Compiler?  

The Mono Project ships an open source C# Compiler among other software such as a .Net Base Class library implementation, a .Net virtual machine and so on. In fact mono ships a number of compilers: gmc, dmc for versions 3.0 and 4.0 of C# respectively. Those are derived from the same source code but are compiled under different configuration. The mono compiler is relatively complete and is likely to parse most of the C# source code one encounters in practice.

Use cases  

An open source C# compiler is useful in a number of scenarios. On big group of applications is analysis of source code. Among this group are intellisense, code metrics and source code analysis applications. Another use of the C# compiler might be for code generation.

Alternatives  

There are no alternative compilers or parsers for C# code that are available for use. The .Net BCL provides interfaces to parsing C# code, but those are not implemented. If Visual Studio is installed one might try to use some of the undocumented COM interfaces that come with it for parsing.

Read more: Codeproject

Posted via email from .NET Info

0 comments: