By the way, for a more generic and transparent solution, you could expose a helper class that provides script-specific list extensions:
and then:
Cheers!
publicstaticclass ListExtensions { publicstaticvoid ForEach<T>(this List<T> list, dynamic function) { list.ForEach(item => function(item)); } }
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); }) ");