Schemat wywołań w języku C# do JS dostępny w Internecie public string GetTimeByJs() { Type obj = Type.GetTypeFromProgID("ScriptControl"); jeśli (obj == null) zwróć 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 }); Wróć do celu. InvokeMember("Eval", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { "time(1, 2, '1 + 2')" }). ToString(); }
Test jest w porządku. czas(1, 2, '1 + 2'), gdzie parametry przekazywane w to (numer 1, numer 2, ciąg 1+2). Ale pojawia się pytanie, nowy obiekt[] { "time(1, 2, '1 + 2')" }, jeśli argument metody JS to typ bajt[], jak powinien być zapisany podczas wywoływania?
|