[Mono-list] late linking & dynamic invocation ...

Michael Meeks michael@ximian.com
27 Jun 2002 09:59:45 +0100


Hi Gonzalo,

	Thanks for your length reply; to re-explain:

On Wed, 2002-06-26 at 21:45, Gonzalo Paniagua Javier wrote:
>         void OnSizeAllocate (EventArgs e)

	this is a sucky way to program; while C is type unsafe, it's easier
than this, we don't have to manually de-marshal arguments from some
generic array of arguments.

	It seems in C# you have to encode the function type from) in 3 places
before you can generically invoke an arbitrary method [ crazy to have
generic Delegate invocation, but no generic Delegate construction ]

	So; you have to ( either admit defeat with the above, uber-broken -
write a de-marshaller in every method scheme ) or:

	a) declare your method - with signature:

		void myAllocateHandler (Widget     w,
				        Allocation a,
					Object     closure)
		{ ... }

	b) declare a Delegate type somewhere [ ok - so this can be
	   done only once in a header somewhere ]

		delegate FooWidgetAllocationObject  
			(Widget w,Allocation a,Object o);

	c) re-type the method signature [ in some mangled form ] in the
	   name of the delegate on connection:

		object.connect (new FooWidgetAllocationObject 
			(myAllocateHandler));

	Ok - so notably, while you have to do more to setup your signal in C [
equivilant to step b ], for step C (yes it is type unsafe) you just do
g_signal_connect (myAllocateHandler) effectively.

	So it seems we need a generic way of creating delegates - I was hoping
to hear the language provided some way to do this - there should be, it
seems trivial to get right.

	Regards,

		Michael.

-- 
 mmeeks@gnu.org  <><, Pseudo Engineer, itinerant idiot