CsCodeGenerator icon indicating copy to clipboard operation
CsCodeGenerator copied to clipboard

Improve writing methods

Open jsteinich opened this issue 7 years ago • 0 comments

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()

jsteinich avatar Apr 05 '18 17:04 jsteinich