Trapped in Delegation hell, any experience would be extremely helpful

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

Trapped in Delegation hell, any experience would be extremely helpful

This post has NOT been accepted by the mailing list yet.
I've been trying to find information on delegation when dealing with C# in Ironpython. The only article I was able to find on the matter was this link http://www.voidspace.org.uk/ironpython/dark-corners.shtml#delegates-and-calltarget0

I don't have direct access to the code i'm trying to provide a delegate to, but I have a basic interface defined by the object browser, which shows it as such:

bool BeginExecuting(Bar object, delegateFunction onFinish)
    Member of SomeClass

public delegate void delegateFunction(FooType result)
    Member of SomeOtherClass

I would like to note that in the VS10 Object Browser, the delegate function/class has "MulticastDelegate" in its Base Types and has methods like 'Invoke', 'EndInvoke', 'BeginInvoke' with 'Invoke' being similar to what I assumed was what I needed to Invoke my delegated function. None of this seemed to offer the solution to my problem when I tried it.

So far, i've tried using the CallTarget0 as outlined in the URL given.  But how this function is using a delegate seems wildly different from how the example shows how to do it.

In the coding example, it shows the closest I got to correct execution before sending this, I was hoping someone could offer more incite into how delegation could be carried out in my case, or even just post some workarounds you managed to work out with difficult code.

coding example:
#... imports etc

    def Check(result):
        print "checker!!"
        print result

    chk = BeginExecuting(theObject, CallTarget0(Check))

#Resulting Error after execution

    chk = BeginExecuting(theObject, CallTarget0(Check))
TypeError: Value cannot be null.
Parameter name: context

I can't figure out if the error refers to how i'm passing the delegation, or something specific to how Ironpython is casting into the result parameter of the 'checker' function. Would also like to note that System.Action does not work in this context and it asks for a 'delegateFunction' where the Action['delegateFunction'] had been provided. I'm assuming that by having access to the C# code, you would implement the function handle this way to open up the facilities to someone using ironpython, so it doesn't apply to my scenario.

I hope I wasn't too vague, and I hope to hear back from someone concerning my problem. Any feedback is appreciated on the matter.