CalliHelper (who?)
While looking around Whidbey documentation, I came across this really goofy looking name: CalliHelper.
What in the world is CalliHelper class? I had no idea.[Update: I am thinking Calli is actually calli IL code (call indirect?)] The only thing it seems to be useful for is to call methods (I tried one of them, There is one more) indirectly. But, we already had delegates for that. Why would this need another such class for this.
Well, Reflector came to the rescue.
It turns out that this is the class used by TemplateControl mother of all Page and UserControl classes, uses this indirectly. It is used by the to call back automatic handlers such as “Page_Load”. All in all, a pretty insignificant class, but it did teach some of the wiring inside.
using System.Web.Util;
using System;
using System.Runtime.InteropServices;
public delegate void TestDelegate();
public class Test
{
[DllImport("msvcrt")]
public static extern IntPtr strncpy(Delegate pd, IntPtr src, int size);
static TestDelegate td;
public Test()
{
}
public static void Main()
{
Test t = new TestEx();
t.DoFunctionCaller();
}
public virtual void TestMe()
{
Console.WriteLine("TestMe was called?");
}
static IntPtr GetFunctionPtrFromDelegate(Delegate d)
{
return d.Method.MethodHandle.GetFunctionPointer();
}
public void DoFunctionCaller()
{
td = new TestDelegate(TestMe);
IntPtr p = GetFunctionPtrFromDelegate(td);
CalliHelper.ArglessFunctionCaller(p,this);
}
}
public class TestEx:Test
{
public override void TestMe()
{
Console.WriteLine("TestEx was called");
}
}