Hey!
In IronPython I am trying to call a PythonFunction with different numbers of arguments from C#. For instance;
I want to do:
def foo(a, b):
print a, b
def bar(a, b, c = None):
print a, b, c
p = App.DynamicEvent()
p.addHandler(foo)
p.addHandler(bar)
p.invoke("Not", "Working")
where addHandler
takes a single argument and somehow stores it in a list of methods to be invoked and invoke
has a signature like this:
public virtual void invoke(params object[] tArgs)
Because I want to avoid making it specific to the PythonEngine
(and thus engine.Operations.Invoke()
), I've tried several ways of storing and implementing these things as delegates but I think the crux of my problem is that I don't know how to store some kind of MulticastDelegate
base type that is compatible with a PythonFunction
?
Perhaps I want to implement my own DynamicInvoke
method? Any thoughts and experience would be greatly appreciated!
The reason for wanting to do this is that I want to transparently map calls made from a sealed Javascript engine into IronPython via C#. i.e. in the Javascript call: Client.doThing("something", 4, {"key:"value"})
and handle it in the python with:
def doThing(s, i, d):
pass
using the following dynamic event binding:
doThingEvent = App.DynamicEvent()
doThingEvent.addHandler(doThing)
WebBrowser.handleMethod("doThing", doThingEvent);