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

New Post: Running List ForEach using script

$
0
0
Greetings!

I guess that the javascript function is not transform into C# Action?

Not automatically. ClearScript provides C#-like type inference, where method overloads are selected according to the argument types. Script functions are not strongly typed, and that presents a problem. To create a callback into script code, you must therefore specify the callback type:
engine.AddHostObject("Datas", new List<string> { "foo", "bar", "baz" });
engine.AddHostType("Callback", typeof(Action<string>));
engine.AddHostType("Console", typeof(Console));
engine.Execute(@"
    Datas.ForEach(new Callback(function(d) {
        Console.WriteLine(d);
    }))
");
Good luck!

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>