Hooking into the C# compiler

Rick said in a comment,

You said: “Philosophically, it would be nice to have some way to leverage the knowledge that the compiler has about the code, but we don't currently have any plans in that area.“

I've often thought that its pretty difficult for tools to do meaningfull things with most source code due to the complexities of parsing. Any chance we'll see the front-end and back-end (and maybe even each phase) of C# compiler be accessible independantly?

I'd like to clarify a bit what I said.

We don't currently have any plans in this area, but we certainly do recognize the utility of providing this sort of access for customers, and would like to be able to do it in the future. And, to answer one of Rick's other questions, Intellisense and refactoring do share the compiler code, but the interface between them is complex and not terribly pretty, and therefore not something we'd like to expose.


Comments (9)

  1. JosephCooney says:

    Like Rick I would really like to see something like this in the future. Maybe if the CSharpCodeProvider could return a valid IParser implementation in future versions of the framework – that would be a good start, and it seems like th "right" place to put it.

    See Daniel Cazzulino’s Weblog Entry:


  2. I’d like to see the C# parser be able to spit out XML representing all the stuff it parsed. That would make it easy to write tools which understand code.

  3. Hey guys,

    In the meantime there is CodeRush addon for VS.NET200x that (amongst many features) exposes partially parsed code (it doesn’t parse expressions for now). It is very-soon-to-be-released.

    Check http://www.devexpress.com/?section=/products/NET/Coderush&reffrom=miha for more info.

  4. I’d like to dump to an XML format the annotated AST (types, symbols, etc), much like I did already for the Java language with the JavaML 2.0 markup language.


    1) A possibility is the C# compiler to generate the XML representation itself, as Graeme Foster suggested.

    2) Another possibility is to implement a Visitor pattern for the AST with access to the symbol table, types table, etc.

    Ademar Aguiar


  5. Of course the compiler should also understand the XML representation… 🙂

  6. Lavos says:

    Hasn’t anyone here seen eXtensible C#? (XC#)

    It runs a post compilation pass through a second compiler that allows you to use declarative attributes to perform some interesting things. Said things include adding statements to methods, obfusticating the generated code, code coverage and style checks, etc. etc.

    I wish I actually had time to use it to give a more accurate statement of what it’s useful for.

  7. Eric Newton says:

    The IParser interface would be nice, in theory the compiler could generate parsed code into CodeDom, then continuing in theory to convert that code into VB.Net… any takers? 😉

  8. MBA says:

    Helpful For MBA Fans.

Skip to main content