One of the unique features in Jint is the ability to 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!"
- Have you ever wondered about the magic happening in the background when injecting C# code into a JS file? Which compiler is responsible for compiling it - C# Compiler or JS?
- When declaring a C# List in a JS file, do you know if the generated object is a JS object or a C# object?