Patcher.Rules.CodeBuilder.Beautify C# (CSharp) Method

Beautify() private method

private Beautify ( string source ) : string
source string
return string
        private string Beautify(string source)
        {
            var builder = new StringBuilder();
            var reader = new StringReader(source);

            int indent = 0;
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                indent -= line.Where(c => c == '}').Count();

                if (indent > 0)
                {
                    var spaces = new string(Enumerable.Range(0, indent * 4).Select(i => ' ').ToArray());
                    builder.Append(spaces);
                }

                builder.Append(line);
                builder.Append("\r\n");

                indent += line.Where(c => c == '{').Count();
            }

            return builder.ToString();
        }