James, Sink<T>(T args) is very similar to Predicate<T>
I had no problems getting that going using IronPython... have a look here: www.base4.net/blog.aspx?ID=118 for an example. Hope that helps Alex -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of James Sent: Thursday, September 28, 2006 1:49 AM To: [email protected] Subject: [IronPython] Creating a Generic Delegate I'm working with Leslie Sanford's excellent C# MIDI library and I'd really like to get things working in IronPython. Here's the incredibly simple code (in C#) required to connect to an input device and call a delegate when a ChannelMessage is received. InputDevice device = new InputDevice(0); device.Connect(delegate(ChannelMessage message) { Console.WriteLine("Command: " + message.Command.ToString()); }); The InputDevice.Connect method has several overloads, so trying a straight function doesn't work, as you can see from this output: >>> from music import * >>> def fn(msg): ... print 'Command: ' + msg.Command.ToString() ... >>> i = InputDevice(0) >>> i.Connect(fn) Traceback (most recent call last): File , line 0, in <stdin>##33 TypeError: multiple overloads of Connect could match (InputDevice, function) Connect(InputDevice, Sink[ChannelMessage]) Connect(InputDevice, Sink[SysExMessage]) Connect(InputDevice, Sink[SysCommonMessage]) Connect(InputDevice, Sink[SysRealtimeMessage]) Connect(InputDevice, Sink[int]) Connect(InputDevice, Sink[Array[Byte]]) A "Sink" is defined as: public delegate void Sink<T>(T arg) So is there any way to make this work? Thanks for any help you can provide. james _______________________________________________ users mailing list [email protected] http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ users mailing list [email protected] http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
