1

I am looking for an engine to run stand-alone JavaScript code from my C# (WinForms) application. The idea behind it, is that the user can provide some script to describe behaviour in the application.

Looking around I can find the JSInterop classes, which seem to do what I want, but I fail to find a good example or even find out if it can do what I want.

So, simple question, could the JSInterop classes work in scenario like this:

var javascript = "function foo() { return 5; }";
var engine = JSInterop.SomeEngine();
var i = engine.run(javascript);

// i is 5 now
Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195
  • [ScriptEngine](https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/windows-scripting/windows-script-engines) could be able to do that as described [here](https://stackoverflow.com/questions/4744105/parse-and-execute-js-by-c-sharp). – NullDev Feb 17 '21 at 13:57
  • 1
    I found `Microsoft.ClearScript` as well. But I know not to ask for library advice here ;-)). I asked specifically about `JSInterop` because I am using other interop libaries already, and they are provided by Microsoft. – Bart Friederichs Feb 17 '21 at 14:03

0 Answers0