Project Description
A library which allows you to work with CodeDOM in a way that is similar to the way you write your code.

The library allows you to write your generated code much faster and make it more readable. Also, the usage of this library is very intuitive.

namespace FluentCodeDom.Sample1
{
    class Program
    {
        static void Main(string[] args)
        {
            CodeCompileUnit compileUnit = new FluentCodeCompileUnit()
                .Namespace("Sample1")
                    .Class("Program")
                        .Method(MemberAttributes.Public | MemberAttributes.Static, "Main").Parameter(typeof(string[]), "args")
                            .CallStatic(typeof(Console), "WriteLine", Expr.Primitive("Hello Fluent CodeDom"))
                        .EndMethod

                        .Method(MemberAttributes.Public | MemberAttributes.Static, "Linq2CodeDomSupport").Parameter(typeof(string[]), "args")
                            .Stmt(ExprLinq.Expr(() => Console.WriteLine("Hello Linq2CodeDOM")))
                            .Declare(typeof(int), "random", ExprLinq.Expr(() => new Random().Next(10)))
                            .If((int random) => random <= 5)
                                .Stmt(ExprLinq.Expr(() => Console.WriteLine("Smaller or equal to 5.")))
                            .Else
                                .Stmt(ExprLinq.Expr(() => Console.WriteLine("Bigger than 5.")))
                            .EndIf
                        .EndMethod
                   .EndClass
                .EndNamespace
            .EndFluent();

            Assembly assembly = Helper.CodeDomHelper.CompileInMemory(compileUnit);
            assembly.GetType("Sample1.Program").GetMethod("Main").Invoke(null, new object[] { null });
        }
    }
}

SEE THE DOCUMENTATION TAB FOR A TUTORIAL

Last edited Mar 26, 2011 at 11:05 PM by Desert_Fox, version 9