CsCodeGenerator
CsCodeGenerator copied to clipboard
Improve writing methods
Using a simple list of lines works well enough for very simple methods, but as soon as you add even a single if, it becomes challenging to keep indents correct. Adding some type of fluent builder could go a long way, i.e.
var method = MethodBuilder.Name("Hello")
.AddLine("if (some condition)")
.AddLine("{")
.AddIndent()
.AddLine("Console.WriteLine(\"Hello World\");")
.RemoveIndent()
.AddLine("}")
.Build()
or
var method = MethodBuilder.Name("Hello")
.AddLine("if (some condition)")
.StartScope()
.AddLine("Console.WriteLine(\"Hello World\");")
.EndScope()
.Build()