public class Program
{
static void CSharpMehtod(string input)
{
Console.WriteLine(input);
}
static void Main(string[] args)
{
var engine = new Engine();
//传递c#函数到js引擎
engine.SetValue("CSharpMehtod", CSharpMehtod);
engine.Execute(@"
CSharpMehtod('call from js');
let jsValue = 111
function jsFunc(a, b) {
return a + b
}
");
//从js引擎中取函数、变量
var jsValue = engine.GetValue("jsValue");
var jsFunc = engine.GetValue("jsFunc");
Console.WriteLine(jsValue);
Console.WriteLine(jsFunc.Invoke(1, 2));
Console.Read();
}
}
标签:engine,jsFunc,CSharpMehtod,Console,js,Jint,jsValue,net
From: https://www.cnblogs.com/trykle/p/16748665.html