Created
February 25, 2017 19:27
-
-
Save joeharrison714/c9bea7320e5f9f1bdc7ae0fbfedf7987 to your computer and use it in GitHub Desktop.
Write code to a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using System.Text; | |
//https://gist.github.com/joeharrison714/c9bea7320e5f9f1bdc7ae0fbfedf7987 | |
internal class CodeWriter | |
{ | |
private readonly StringBuilder _output; | |
private int _indents; | |
public CodeWriter() | |
{ | |
_output = new StringBuilder(); | |
} | |
public void WriteFile(string filename) | |
{ | |
File.WriteAllText(filename, _output.ToString()); | |
} | |
public void IncreaseIndent() | |
{ | |
_indents++; | |
} | |
public void DecreaseIndent() | |
{ | |
_indents--; | |
} | |
public void WriteEmptyLine() | |
{ | |
WriteLine(""); | |
} | |
public void WriteLine(string line) | |
{ | |
WriteLine(line, new object[0]); | |
} | |
public void WriteLine(string line, params object[] args) | |
{ | |
for (int i = 0; i < _indents; i++) | |
{ | |
_output.Append("\t"); | |
} | |
if (args.Length > 0) | |
{ | |
line = string.Format(line, args); | |
} | |
_output.AppendLine(line); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment