To expose public functions and members + Dynamic ones (ObjectInstance) #2186
bucheronbanlieusard
started this conversation in
General
Replies: 2 comments 2 replies
-
|
Edit: Oops probably not, I forgot |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Some options: using Jint;
using Jint.Runtime.Interop;
var e1 = new Engine();
var timeSpan = ObjectWrapper.Create(e1, TimeSpan.FromMinutes(1));
timeSpan["extra"] = 42;
e1.SetValue("ts", timeSpan);
Console.WriteLine(e1.Evaluate("ts.totalSeconds"));
Console.WriteLine(e1.Evaluate("ts.extra"));
var e2 = new Engine(options => options.SetWrapObjectHandler(static (engine, target, type) =>
{
var wrapper = ObjectWrapper.Create(engine, target);
wrapper["extra"] = 24;
return wrapper;
}));
e2.SetValue("ts", TimeSpan.FromMinutes(2));
Console.WriteLine(e2.Evaluate("ts.totalSeconds"));
Console.WriteLine(e2.Evaluate("ts.extra")); |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'm using:
engine.SetValue("test", new Test());
to expose, in js, a list of public functions and members and it's working nice! But I need to be able to expose dynamically other members. Using ObjectInstance with
public override JsValue Get(JsValue property, JsValue receiver)
At the moment I inherit Test from ObjectInstance, the public functions and members of Test aren't available anymore.
Can we have both at the same time, like to fallback on the public functions and members if not overrided in the Get function? base.Get doesn't do it.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions