1

Is it possible to set up formatting options for C# code generation without spaces and line breaks?

I mean the transformation of the following code:

using System;
class Test
{
    public void Main(string[] args)
    {
         Console.WriteLine("Hello, World");
    }
}

to this code:

using System;class Test{public void Main(string[] args){Console.WriteLine("Hello, World");}}

I am trying to do it with empty options, but it is does not work.

SyntaxTree syntaxTree;
CSharpFormattingOptions emptyOptions = FormattingOptionsFactory.CreateEmpty();
sting CSharpCode = syntaxTree.GetText(emptyOptions);
Ivan Kochurkin
  • 4,413
  • 8
  • 45
  • 80
  • 4
    Just out of curiosity, why on earth would you want to do this? – Kjartan Oct 16 '13 at 13:12
  • 1
    @Kjartan, for automatic conversation of usual C# code to it's own minified version, which can be used in such freaky programs as an easy quine or complex [selfprinting game of life](http://igoro.com/archive/self-printing-game-of-life-in-c/). Space and line breaks removing is one of several automatic minification steps. – Ivan Kochurkin Oct 16 '13 at 13:19

1 Answers1

0

I created project for C# code minification based on NRefactory: CSharpMinifier

Code for whitespace removing located in this file: Minifier.cs

Ivan Kochurkin
  • 4,413
  • 8
  • 45
  • 80