convert arguments to c# array?

Feb 6, 2016 at 10:18 AM
hi,

how can i convert the js arguments object to an c# array?
Coordinator
Feb 7, 2016 at 4:47 PM
Hi furesoft,

Here's a sample that sets up a script-callable function for converting any array-like JavaScript object to a .NET array:
engine.Script.toClrArray = new Func<dynamic, object>(obj => {
    var result = new object[obj.length];
    for (var i = 0; i < result.Length; ++i)
        result[i] = obj[i];
    return result;
});
And here's how you might use it from script code:
engine.Execute(@"
    function MakeClrArray() {
        return toClrArray(arguments)
    };
    var foo = MakeClrArray(1, 2, 3, 'bar', Math.PI);
");
Good luck!