To call static method of the current class you can use Call method in CodeDom helper class. More about CodeDom, Emit, Define classes see in my blog.
In example below we define two methods. Method foo calls method zoo.
static void Main()
{
    var c = new CodeDomGenerator();

    c.AddNamespace("TestNS").AddClass("cls")
        .AddMethod(MemberAttributes.Public | MemberAttributes.Static, () => "foo",
            Emit.stmt(()=>CodeDom.Call("zoo")())
        )
        .AddMethod(MemberAttributes.Public | MemberAttributes.Static, () => "zoo")
    ;

    Console.WriteLine(c.GenerateCode(LinqToCodedom.CodeDomGenerator.Language.CSharp));
}
Instance methods can be invoked via @this special property in CodeDom class.
.AddMethod(MemberAttributes.Public, () => "foo",
    Emit.stmt(()=>CodeDom.@this.Call("zoo")())
)
.AddMethod(MemberAttributes.Public, () => "zoo")
}
The resulting c# code
namespace TestNS {
    public class cls {

        public virtual void foo() {
            this.zoo();
        }

        public virtual void zoo() {
        }
    }
}
And here is VB.NET code
Namespace TestNS

    Public Class cls

        Public Overridable Sub foo()
            Me.zoo
        End Sub

        Public Overridable Sub zoo()
        End Sub
    End Class
End Namespace

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

Comments

No comments yet.