A C# call to JS scheme found on the Internet public string GetTimeByJs() { Type obj = Type.GetTypeFromProgID("ScriptControl"); if (obj == null) return null; object ScriptControl = Activator.CreateInstance(obj); obj. InvokeMember("Language", BindingFlags.SetProperty, null, ScriptControl, new object[] { "JavaScript" }); string js = "function time(a, b, msg){ var sum = a + b; return new Date().getTime() + ': ' + msg + ' = ' + sum }"; obj. InvokeMember("AddCode", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { js }); return obj. InvokeMember("Eval", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { "time(1, 2, '1 + 2')" }). ToString(); }
The test is fine. time(1, 2, '1 + 2'), where the parameters passed in are (number 1, number 2, string 1+2). But there is a question, new object[] { "time(1, 2, '1 + 2')" }, if the argument of the JS method is of type byte[], how should it be written when calling?
|