C# code generator

Check out Using CodeDOM to generate CSharp (C#) and VB code.


You may want to have a look csscript that relies on CodeDOM.

It allows you to write things like:

var PrintSum = CSScript.LoadMethod(
        @"public static void PrintSum(int a, int b)
          {
              Console.WriteLine((a+b));
          }")
          .GetStaticMethod();
PrintSum(1, 2);

Be sure to read the doc, it's pretty detailed and you'll find you can do a lot more than what I just copied before.


T4 or Text Template Transformation Toolkit might be worth looking into.

Another option is to create your own simple generator, which contains functionality more suited for your situation than the CodeDOM. In a recent code generation project that's what I did, however I have encapsulated the code generation to make it possible to later transition to CodeDOM.