我正在开发一个使用Javascript.net (以前的Noesis .net)作为脚本引擎的项目。
如何将C#方法添加到Javascript中的全局上下文中?例如,假设我在C#中有:
public int Foo(int bar)
{
return bar * 2;
}我想打电话给Javascript:
var x = 5;
var y = Foo(x); // y is now 10;在侏罗纪等其他图书馆,这是可能的:
engine.SetGlobalFunction("Foo", new Func<int, int>((a) => a*2));发布于 2020-05-22 23:22:51
此示例来自单元测试:
_context.SetParameter("f", new Func<string,string>((s) => s.ToUpper()));
_context.Run("f('Noesis') == 'NOESIS'").Should().BeOfType<bool>().Which.Should().BeTrue();https://stackoverflow.com/questions/61954274
复制相似问题