Project Description
The library helps to create CodeDOM graph and generate code from it. It uses expression trees in form of lambda functions to create CodeDOM tree.

Objective

The library helps developers to write dynamic source code generators based on Microsoft CodeDOM.

Features

  • Easy of use
  • Compile time check
  • How to

Sample

CodeDOM is a abstract tree of language independent structures that can be converted to source code via corresponding code providers.
Expression tree is abstract tree of language independent structures that can be converted to everything (text, structural data, code, etc).
The library converts expression tree to CodeDOM tree. Here is an example
        static void Main()
        {
            var c = new CodeDomGenerator();

            c.AddNamespace("Samples").AddClass("TestClass")
                .AddMethod(MemberAttributes.Public | MemberAttributes.Static, ()=>"Print",
                    Emit.stmt(() => Console.WriteLine("Hello, world!")),
            );
        }
The program generates following code
//--------------------------------------------------------------------------

// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.3074
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//--------------------------------------------------------------------------


namespace Samples {


    public class TestClass {

        public static void Print() {
            System.Console.WriteLine("Hello, world!");
        }
    }
}
The idea is my own. Some initial peaces of code was stolen from Expression Trees-Lambdas to CodeDom Conversion and CodeDom extensions and dynamic LINQ (string/script to LINQ emitting)

Last edited May 13, 2009 at 3:18 PM by AlexShirshov, version 10