Hi blackshade,
.NET's dynamic infrastructure provides a convenient way to access script objects in a way that's both .NET-friendly and engine-neutral. A dictionary-style interface might also be convenient, but it's not clear what advantage it would have over the combination of
The problem with your
This implementation is simpler and takes advantage of inline caching to speed up repeated calls. In our experiments it's about 22x faster on average in Release builds.
Still, using JSON tunneling as you suggest makes sense in many cases. ClearScript provides live access to script objects, but if all you need is a snapshot, then JSON is a great way to minimize marshaling and improve performance.
Thanks for your question, and good luck!
Why the use of dynamics?
.NET's dynamic infrastructure provides a convenient way to access script objects in a way that's both .NET-friendly and engine-neutral. A dictionary-style interface might also be convenient, but it's not clear what advantage it would have over the combination of
GetDynamicMemberNames()
and dynamic indexing.The problem with your
GetMember()
method is that it recreates the binder and callsite each time. Try this instead:privatestaticobject GetMember(object o, string propName) { return ((dynamic)o)[propName]; }
Still, using JSON tunneling as you suggest makes sense in many cases. ClearScript provides live access to script objects, but if all you need is a snapshot, then JSON is a great way to minimize marshaling and improve performance.
Thanks for your question, and good luck!