Is there way to format code with line-breaks and indentation produced by ExpressionToCode

495 views Asked by At

Is there way to format code produced by ExpressionToCode? In particular to add line-breaks and indentation as following:

var code = ExpressionToCode.ToCode(() => new A(new B(), new C()));

and the result code is:

() => 
    new A(
        new B(),
        new C())
1

There are 1 answers

0
Luaan On BEST ANSWER

Not really. You could take the Roslyn SyntaxTree (using ToSyntaxTree instead of ToCode) and use that to format the output any way you want.

It's actually quite easy to handle code formatting with Roslyn - you just have to inherit your own class from SyntaxRewriter. See http://www.christophdebaene.com/blog/2011/10/26/roslyn-formatting-code/ for more information.

The problem of code formatting is actually quite complex, it needs quite a bit of thought.