Hello
Thanks, Perfect :-)
Sybaris
Thanks, Perfect :-)
Sybaris
I noticed that when calling (from .NET) a JavaScript function that talks to .NET objects, it seems to take about an extra 100ms on the first call. Is this because the proxies are set up on demand? Just curious.
Really this is a specific example of a general question - is it better to do such work on the C# side and expose simpler objects and interfaces to JavaScript?
scriptEngine.AddHostObject("DotNet", new HostTypeCollection("mscorlib", "System.Core", "System.Data"));
But for adding columns, the Add method require a Type Parameter.var dt = new DotNet.System.Data.DataTable("testDataTable");
dt.Columns.Add("Col1",DotNet.System.Int32);
The last line does not run 'invalid argument.dt.Columns.Add("Col1",typeof(System.Int32));
How can I do the same of typeof in ClearScript / Javascript ?HostFunctions
class provides a number of utility methods for situations like this, including typeOf()
. The only other thing to be aware of is that ClearScript blocks reflection by default, but you can easily enable it:scriptEngine.AddHostObject("host", new HostFunctions()); scriptEngine.AllowReflection = true; scriptEngine.Execute(@" var dt = new DotNet.System.Data.DataTable('testDataTable'); dt.Columns.Add('Col1', host.typeOf(DotNet.System.Int32)); ");
ThisScript = Engine.Compile(scriptFile)
Engine.Execute(ThisScript)
When the timer is on I use the Script method to call a specific function name in the main script. The user understands that if they want to run a script every scan it must be in the main script and a function named Main() must exist in that script.