Uno schema chiamata a JS in C# trovato su Internet stringa pubblica GetTimeByJs() { Tipo obj = Tipo.GetTypeFromProgID("ScriptControl"); se (obj == null) restituisca null; oggetto ScriptControl = Attivator.CreateInstance(obj); Obj. InvokeMember("Language", BindingFlags.SetProperty, null, ScriptControl, new object[] { "JavaScript" }); stringa js = "funzione tempo(a, b, msg){ var sum = a + b; return new Date().getTime() + ': ' + msg + ' = ' + somma }"; Obj. InvokeMember("AddCode", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { js }); Ritorna obj. InvokeMember("Eval", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { "time(1, 2, '1 + 2')" }). ToString(); }
Il test va bene. tempo (1, 2, '1 + 2'), dove i parametri passati sono (numero 1, numero 2, stringa 1+2). Ma c'è una domanda, new object[] { "time(1, 2, '1 + 2')" }, se l'argomento del metodo JS è di tipo byte[], come dovrebbe essere scritto quando si chiama?
|