As you see there is a space after the 'null' that shouldn't be there. I could've just removed the space and continue my work - but what would happen if I do it again ? Wouldn't it be nice if it could be auto formatted like in a IDE. Just make the code format itself!
First step - make the program print itself. For that I added some code around the if that repeats the program and prints it:Now running the program on the console gives: The self formatting source code - easy and without any external IDE. The wrong space is finally gone. But the formatter has done something with the brackets. That's because of the options I gave to the formatter. The C# formatter needs an options object that specifies how the C# code should be formatted. The CSharpFormattingOptions class provides a large set of very fine grained formatting options. The factory gives easy access to the most common indenting styles (see wikipedia). The Allman style is used in Visual Studio .NET which puts all braces on it's own line. That's why the formatter has altered the if brackets. That's just one way to call the formatter. It was built for in IDE use. The formatter can generate the minimum change set of replace operations required to do the formatting. Furthermore it's possible to format only a portion of the text inside a document. In monodevelop the on the fly formatter uses this functionality to provide formatting. The formatting engine in NRefactory is mighty and easy to use - let me know if you find uses for it or have improvements.