I'm trying to access a Javascript
array
through Jint
. We're basically accepting custom javascript
code in an application that works across a variety of platforms and are using Jint
for .NET
. We need the result to be the same - whether it's in .NET
or vanilla JavaScript
.
private Engine _engine = new Engine();
var testList = new List<int> { 1, 2, 3, 4, 5 };
_engine.SetValue("testList", testList);
var result = _engine.Execute("'Elements of the array are: ' + testList").GetCompletionValue();
var finalVal = result.AsString();
I would expect the result to be:
Elements of the array are: 1,2,3,4,5
(similar to vanilla JavaScript
)
However, it throws an exception.
System.InvalidOperationException: No matching indexer found.
Note that if I try to access just one element of the array (eg testList[1]
) it works fine.
Am I doing something wrong here? If not, then can I implement a custom indexer to make this work?