[Mono-list] Casting delegates
Jonathan Pryor
jonpryor@vt.edu
Wed, 16 Feb 2005 07:00:35 -0500
On Tue, 2005-02-15 at 21:22 +0100, Kris Luyten wrote:
> It seems mcs can not compile statements of the following structure:
> "((PInputEventHandler)each)(this, e);" where each is of type Delegate,
> and PInputEventHandler is defined as "public delegate void
> PInputEventHandler(object sender, PInputEventArgs e);".
In the immortal words of...someone, "It Works For Me" (TM).
In particular, the following code compiles under both Mono 1.1.1 and
svn-trunk:
// delegate casting...
using System;
delegate void PInputEventHandler (object sender, EventArgs e);
class Test {
public static void Main ()
{
Test t = new Test ();
Delegate d = new PInputEventHandler (Handler);
((PInputEventHandler)d) (t, null);
}
private static void Handler (object sender, EventArgs e)
{
}
}
Your code should work.
- Jon