Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: convert arguments to c# array?

$
0
0
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 = newobject[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!

Viewing all articles
Browse latest Browse all 2297

Trending Articles