This project is read-only.

export array with properties ?

May 9, 2012 at 6:10 AM

I have a c# object exposed using .SetParameter() with a method that returns an Array.

At some point, after calling this method, the JS code calls another method which passes in the original array, but needs to track to original array using a named property.

In pure javascript, I would simply add a property to the array itself before passing it around:

var arr = [];
arr.push('value');
arr.name = 'my array';

But the c# method needs to return an IList:

IList GetArray();

 

Could this IList have properties exposed to JS ??

May 9, 2012 at 6:52 AM

JavascriptInterop::ConvertArrayFromV8() converts JavaScript arrays into CLR arrays.  I'm not sure why you are seeing it as an IList, although of course arrays do implement IList.  This scheme has the advantage of obviousness.  In principal we could return some object that provided array indexing and a dictionary for extra attributes to better match JavaScript, but these would be slower and would be confusing and harder to use, im my opinion.

e.g. you could no longer write

int[] a = (int[])context.Run("[1,2,3]");

and would instead need to work in terms of an IList.