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

New Post: Running List ForEach using script

0
0
By the way, for a more generic and transparent solution, you could expose a helper class that provides script-specific list extensions:
publicstaticclass ListExtensions {
    publicstaticvoid ForEach<T>(this List<T> list, dynamic function) {
        list.ForEach(item => function(item));
    }
}
and then:
engine.AddHostType("ListExtensions", typeof(ListExtensions));
engine.AddHostType("Console", typeof(Console));
engine.AddHostObject("Datas", new List<string> { "foo", "bar", "baz" });
engine.Execute(@"
    Datas.ForEach(function(d) {
        Console.WriteLine(d);
    })
");
Cheers!

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images