Hi James2015Li,
The native value of a JavaScript number is double-precision floating-point. When you pass such a value to a .NET method, ClearScript converts it to one of the following managed types, choosing the first one that results in no numeric data loss:
The
Good luck!
The native value of a JavaScript number is double-precision floating-point. When you pass such a value to a .NET method, ClearScript converts it to one of the following managed types, choosing the first one that results in no numeric data loss:
System.Int32
System.Int64
System.Single
System.Double
System.Int32
, which is not implicitly convertible to System.Int16
, so the call fails. However, ClearScript provides a helper function you can use in this scenario:engine.AddHostObject("host", new HostFunctions()); engine.Execute("Me.SetValue(host.toInt16(123));");
HostFunctions
class includes methods for converting script numbers to most managed numeric types. Unfortunately at the moment there's no way to change the default conversion algorithm.Good luck!