/CodeWriter

Helper class for generating code concisely.

Primary LanguageC#MIT LicenseMIT

CodeWriter

NuGet Status Build status Coverage Status Coverity Status

CodeWriter is a small helper class for generating code concisely. It helps writing neat code which generates code dynamically.

Following code generates C# code on the fly:

var w = new CodeWriter.CodeWriter(CodeWriterSettings.CSharpDefault);
using (w.B("class Test"))
{
    using (w.B("public static int Sum(int a, int b)"))
    {
        w._("var r = a + b;",
            "return r;");
    }
}
Console.Write(w.ToString());

Output:

class Test
{
    public static int Sum(int a, int b)
    {
        var r = a + b;
        return r;
    }
}

Where can I get it?

PM> Install-Package CodeWriter