当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Communication between Jint and JavaScript

问题描述:

I am looking for a way to communicate (back and forth) between Jint and C#.

Is there a way? I have no problem of running JavaScripts in Jint after loading them to the engine but I still have an issue getting the callbacks on the other hand - from the JavaScript back to C#(maybe using some kind of ObjectForScripting? or other predefined settings?)

Thanks

网友答案:

In C#, provide a class with a method you want to run.

public class JavaScriptHelper {
    public string Method(string input) {
        return String.Concat("Hi", input);
    }
}

Then pass the class to the engine.

var engine = new Engine();
engine.SetValue("helper", new JavaScriptHelper());
var source = @" var result = helper.Method('Hello');"
engine.Run(source);
分享给朋友:
您可能感兴趣的文章:
随机阅读: