Roslyn Code Quoter updated to work with September 2012 CTP

Roslyn Code Quoter updated to work with September 2012 CTP

  • Comments 1

I’ve blogged before about the tool called Quoter that shows how to use the Roslyn Syntax APIs to construct syntax trees manually:

http://blogs.msdn.com/b/kirillosenkov/archive/2012/07/22/roslyn-code-quoter-tool-generating-syntax-tree-api-calls-for-any-c-program.aspx

I’ve updated the source to work with the latest (September 2012) Roslyn CTP:

http://code.msdn.microsoft.com/Roslyn-Code-Quoter-f724259e

Apart from several API changes I’ve also made it remove redundant calls, such as calls to insert { and } into new type declarations (they’re added by default already). Thus, the generated code is now shorter. For the source code “class C { }” we now generate:

Syntax.CompilationUnit()
  .WithMembers(
    Syntax.List<MemberDeclarationSyntax>
      Syntax.ClassDeclaration(
        @"C")))
  .NormalizeWhitespace()

which is way shorter than it used to be. I also made it not preserve whitespace/formatting by default (it will now generate trees without whitespace and then apply default formatting). If you’d like to preserve the exact whitespace of your source program, you need to set UseDefaultFormatting = false.

Enjoy!

  • This is really great work!

Page 1 of 1 (1 items)
Leave a Comment
  • Please add 3 and 8 and type the answer here:
  • Post