Reputation: 221
In Jint, you can access .Net classes in JS.
JS File Code :
var write = function (msg) {
var log = System.Console.WriteLine;
log(msg);
};
C# Code
Engine jsEngine = new Engine(e=>e.AllowClr());
string script = System.IO.File.ReadAllText("file1.js");
jsEngine.Execute(script);
jsEngine.Invoke("write", "Hello World!"); //Displays in Console: "Hello World!"
Upvotes: 3
Views: 1350
Reputation: 2317
Let's walk through the Invoke call step by step:
Now to your questions:
Upvotes: 0
Reputation: 5146
You are not injecting C# code, the Jint interpreter will understand that you are reference to a .NET class, and hence execute this code. Because Jint is written in .NET it can run any .NET code you are asking.
Also Jint doesn't compile anything, it reads every javascript statement and tries to evaluate them one after the other, keeping track of all variables, functions and other JS artifacts your are declaring and using.
Upvotes: 1