In IronJS, we have a custom object derived from CommonObject. We're wanting to intercept calls to undefined properties on the object, and provide dynamic responses. (This is required, as it is not possible in our situation to preregister all the properties.)
We can capture function calls on this object by overriding the BoxedValue Get(string name)
function, and provide functions "on the fly" without preregistering them on the object.
We're hoping we can do the same with properties, but none of the overrides seem to be able to handle this. I'm hoping that someone has enough experience with IronJS to suggest how we can better approach this.
Hopefully this clarifies what we're trying to achieve:
IronJS.Hosting.CSharp.Context ctx = new IronJS.Hosting.CSharp.Context();
ctx.SetGlobal("data", new MyCustomObject());
string script = @"var x = data.mydynamicproperty;";
ctx.Execute(script);
When the script executes, we are wanting to be able to override and return a custom value. For example (on the MyCustomObject class declaration):
public override BoxedValue Get(string name) {
if (name == "mydynamicproperty") {
return BoxedValue.Box("test");
}
}
The above override is called for functions (e.g. var x = data.mydynamicfunction();
) but not for properties.
Any help or suggestions would be greatly appreciated.