-
Hi all, I'm in the process of upgrading Jint from 3.0.0-beta-2033 to 4.0.1 and since ProxyInstance/JsProxy is now internal, I'm having some trouble trying to convert the logic we had at one point. I want to access CLR objects as so -- In 3.0.0-beta we were able to do this: private JsValue CreateDogsProxy(
Engine engine,
IConverter converter,
IAdoptablePetCollection adoptablePets)
{
var handler = new ObjectInstance(engine);
JsValue GetterFunc(JsValue _, JsValue[] arguments)
{
var name = (JsString)arguments[1];
var result = adoptablePets.Dogs.SingleOrDefault(v => v.Name == name;
if (result is null)
return JsValue.Undefined;
var dog = converter.Convert(engine, adoptablePets, result); // uses a converter to get the Dog object as JsValue
return dog;
}
handler.Set("get", new ClrFunctionInstance(engine, "_get_", GetterFunc));
return new ProxyInstance(engine, new ObjectInstance(engine), handler);
} And then in JavaScript - Now since ProxyInstance/JsProxy is internal, I can't use this in the same way. I've tried creating my own proxy and also setting the "get" property for the object itself and nothing seems to hit the GetterFunc. What's the best way now to override the getter/setter for an object? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I've never thought Proxies being that convenient on interop side as there's already |
Beta Was this translation helpful? Give feedback.
I've never thought Proxies being that convenient on interop side as there's already
ObjectWrapper
. Have you considered deriving from it and overriding relevantGet
methods? Would probably be more performant too without all the abstractions.