次の方法で共有


Roslyn Code Quoter updated to work with September 2012 CTP

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

https://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:

https://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!

Comments

  • Anonymous
    January 06, 2013
    This is really great work!