This project has moved and is read-only. For the latest updates, please go here.

Type argument : how to make a typeof

Sep 10, 2015 at 12:27 PM
Edited Sep 10, 2015 at 12:29 PM

I exposed DataTable type to my javascript code :
C# code :
scriptEngine.AddHostObject("DotNet", new HostTypeCollection("mscorlib", "System.Core", "System.Data"));
But for adding columns, the Add method require a Type Parameter.
My Javascript code :
var dt = new DotNet.System.Data.DataTable("testDataTable");
The last line does not run 'invalid argument.
In C#, I should write this :
How can I do the same of typeof in ClearScript / Javascript ?

Thanks for advance
PS : I discover ClearScript for a few days, and I am very impressed by all the work made, and the power of this engine...
Sep 10, 2015 at 1:05 PM
Hi Sybaris,

ClearScript's 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;
    var dt = new DotNet.System.Data.DataTable('testDataTable');
    dt.Columns.Add('Col1', host.typeOf(DotNet.System.Int32));
Marked as answer by sybarisfr on 3/30/2016 at 10:57 PM
Sep 10, 2015 at 1:11 PM
Perfect :-)

Thanks a lot