With Jint how can I set a property (or invoke a method) of an instance of a javascript class?
e.g. if I do:
var o = new Jint.Engine().Evaluate(@"
class MyClass {
constructor() {
this.myProperty = null;
}
}
const o = new MyClass;
return o;
");
how do I then set the myProperty value of the returned o object?
This is using Jint v3.
To access stuff you got back from Jint, you turn it into an object by calling
ToObject()on it and declare it as dynamic so you can use arbitrary properties:Now AFAIK there is no built-in way to change a property and continue working with it in the Javascript. Two options I can think of:
Declare the class in C# and pass an instance to Jint via SetValue(). Changes to the object instance will be available in Jint.
Hack up something like this to change arbitrary stuff from within Jint: