public static string FormatCodeWithNRefactory(string code, ref int pos) { //https://github.com/icsharpcode/NRefactory/blob/master/ICSharpCode.NRefactory.CSharp/Formatter/FormattingOptionsFactory.cs //it is all great though: // all empty lines are lost // Fluent calls are destroyed // cannot handle classless: if any parsing error happens the generation result is completely unpredictable (the cone can be even lost) // Does not allow mixed brace styles despite BraceStyle.DoNotCHange // Hard to trace 'pos' // var option = FormattingOptionsFactory.CreateAllman(); option.BlankLinesAfterUsings = 2; //BraceStyle.NextLine //option.SpaceWithinMethodCallParentheses = true; //option.BlankLinesBeforeFirstDeclaration = 0; //option.BlankLinesBetweenTypes = 1; //option.BlankLinesBetweenFields = 0; //option.BlankLinesBetweenEventFields = 0; //option.BlankLinesBetweenMembers = 1; //option.BlankLinesInsideRegion = 1; //option.InterfaceBraceStyle = BraceStyle.NextLineShifted; var syntaxTree = new CSharpParser().Parse(code, "test.cs"); return(syntaxTree.GetText(option)); }