In my 'myClass' class, I am using Reflection.Emit to dynamically write an event handler for one of the myClass class' members.
I have done this successfully.
Now, I want to modify the event handler to call one of the instance methods in the myClass class.
However, I cannot figure out how to push a reference to 'this' onto the MSIL stack using Reflection.Emit. Within the event handler, Ldarg_0 is not a reference to 'this', but rather the first parameter of the event handler.
Does anyone know how to push a reference to 'this' on the stack so that I can call an instance method. For example, this is what I would want the c# code to look like:
public class myClass
{
private myObj1 obj1;
public myClass() {
this.init();
}
private void init()
{
obj1.myEvent += new myEvent_EventHandler(theHandler);
}
private void theHandler(myObj2 obj2, myObj3 obj3)
{
// this is the part I'm having trouble with
this.myFunction(obj2);
}
private void myFunction(myObj2 obj2)
{
// irrelevant
}
}
Thanks!