views:

164

answers:

1

Duplicate

C# to format (indent, align) C# properly


I am generating a bunch of code and would like it's initial output (pre ctrl+K, Ctrl+D) to look reasonable. Managing indents is a royal pain and there has to be a utility or class out there I can embed inside of my code generator. I am embedding this into a VS add-in and in a build process so I am not interested in an external program. I need something I can call programatically.

Recommendations?

+1  A: 

Use the IndentedTextWriter that is provided with the Microsoft .NET Framework to help with indenting code. There is sample usage included with the class documentation.

Atif Aziz
That's not going to be terribly useful without writing a parser to understand C# syntax and therefore decide when to indent/unindent.
Noldorin
Right, I misunderstood the question.
Atif Aziz