Taritsyn/MsieJavaScriptEngine

Anonymous Host Objects

rhett-thompson opened this issue · 1 comments

It doesn't look like you can embed anonymous objects with EmbedHostObject at present.

Is the best way to do this to serialize the object to json and include in the js being executed?

Thanks.

Hello, Rhett!

Anonymous types differ little from other .NET types. In my opinion there is only one significant difference: “Properties of anonymous type are read only and they cannot be set”.

It doesn't look like you can embed anonymous objects with EmbedHostObject at present.

It works for me. I even wrote a unit test to verify this. But it is worth noting, that current version of the EmbedHostObject method does not support projection of collection types.

Is the best way to do this to serialize the object to json and include in the js being executed?

EmbedHostObject method it is recommended to use for embedding of active objects (for example, objects with methods, that you will call from the script). If you just need to pass data to the script, then it is better to use JSON serialization (this will require less resources).

I also recommend you to see a real example of using the EmbedHostObject method and JSON serialization.