Method can be defined via Define static class.
CodeMemberMethod method = Define.Method(MemberAttributes.Public, () => "foo");
There is also extension AddMethod in CodeTypeDeclaration class
CodeTypeDeclaration cls = Define.Class("cls");
CodeMemberMethod method = cls.AddMethod(Define.Method(MemberAttributes.Public, () => "foo"));
AddMethod has overload to avoid Define.Method call
CodeTypeDeclaration cls = Define.Class("cls");
CodeMemberMethod method = cls.AddMethod(MemberAttributes.Public, () => "foo");
So the whole program my looks like
static void Main()
{
    var c = new CodeDomGenerator();

    c.AddNamespace("TestNS").AddClass("cls")
        .AddMethod(MemberAttributes.Public, () => "foo");

    Console.WriteLine(c.GenerateCode(LinqToCodedom.CodeDomGenerator.Language.CSharp));
}

Last edited May 16, 2009 at 10:01 AM by AlexShirshov, version 2

Comments

No comments yet.