c# - Passing JSON from Javascript Callback in JINT -
i have library allows developer extend business rule triggers via javascript. there function allows developer (in javascript) subscribe event , pass delegate "call me when happens".
i able successfully, running snag when function attempts pass json or javascript object c# layer.
basically code functions unit test:
func<string, jsvalue> callback = null; func<func<string, jsvalue>, object> registercallback = (o) => callback = o; engine engine = new engine() .setvalue("registercallback", registercallback) .execute("registercallback(function(parameter) { return { \"passed\": parameter }; });"); assert.isnotnull(callback); var result = callback("test");
i c# variable "result" have jsvalue or other object contains data method throws exception: must implement iconvertable on last line.
i can verify "callback" set delegate of appropriate type: jint.native.jsvalue lambda_method(system.runtime.compilerservices.closure, system.string)}
and don't have issue if pass null. i'm sure there tiny (headbang once figure out) missing piece...
change jsvalue
system.dynamic.expandoobject
. type of result
, , can safely cast idictionary<string, object>
.
Comments
Post a Comment