For type and member declaration there is Define static class.
Below is example how to define class cls
CodeTypeDeclaration cls = Define.Class("cls");
There is another approach to define class - use extension method AddClass of type CodeNamespace
CodeNamespace ns = new CodeNamespace("TestNS");
CodeTypeDeclaration cls = ns.AddClass(Define.Class("cls"));
AddClass extension also can accept class name parameter
CodeNamespace ns = new CodeNamespace("TestNS");
CodeTypeDeclaration cls = ns.AddClass("cls");
The code can be generated via CodeDomGenerator class. CodeDomGenerator has AddNamespace method so the whole program may looks like
static void Main()
{
    var c = new CodeDomGenerator();

    c.AddNamespace("TestNS").AddClass("cls");

    Console.WriteLine(c.GenerateCode(LinqToCodedom.CodeDomGenerator.Language.CSharp));
}
And the resulting code is
namespace TestNS {
    public class cls {
    }
}
All high level abstructions and their relationships defined in my blog.

Last edited May 16, 2009 at 10:41 AM by AlexShirshov, version 5

Comments

No comments yet.