Taritsyn/MsieJavaScriptEngine

How to get data back from JS to C#?

andreykorolev opened this issue · 1 comments

I have executed the following script:
var obj = { n: 123, s: 'str' }
GetVariableValue("obj") has returned COM Object.

How can I get data from JS to C# as ExpandoObject or Dictionary<string, object>?

Hello, Andrey!

In no way. Supports only primitive types.

But it is possible serialize the object to a string:

JSON.stringify(obj);

And then deserialize the string result by using the Json.NET library:

var json = JObject.Parse(result);

As an example, I recommend you see the source code of the BundleTransformer.Less. There used the JavaScript Engine Switcher, but it has a very similar API.