Common functionality in custom derived ObjectInstances

Nov 6, 2011 at 12:01 PM

I need to add some common functionality to several custom ObjectInstances. Specifically, what I need is eventing.

What I want, is functionality so that I can write JS like so:

obj.listen('connect', function (param1, param2, paramN) {
    // Do something usefull

and on the C# side I would like to have a function that I can call like this:

this.Fire('connect', param1, param2, paramN);
Now, I have no problem with implementing the Listen and the Fire methods myself, but what I need is some way to to map this all together. Like, say I have a class SeverConnection for instance, that extends ObjectInstance. How would I go about adding the eventing-functionallity to that class (whithout having to manually implement it everywhere), so that it works both on the js side, and on the C# side?

Nov 6, 2011 at 8:09 PM

The documentation for interoping with JavaScript is here:

I'm not quite sure what you mean when you say "whithout having to manually implement it everywhere".  Couldn't you just have a base class that inherits from ObjectInstance and has the desired functionality?

Nov 6, 2011 at 8:44 PM

I tried that, but PopulateFunctions don't go up trough inheritance-chain in C#, thus resulting in the js-code not working (obj.listen is not defined).

Nov 6, 2011 at 9:26 PM

Ah, I see your problem now.  See here for some discussion on this problem:  Does this solve your problem?