Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

Expandoobject #1018

Open
thelazydogsback opened this issue Oct 2, 2016 · 3 comments
Open

Expandoobject #1018

thelazydogsback opened this issue Oct 2, 2016 · 3 comments

Comments

@thelazydogsback
Copy link

Trying:
dynamic e = new ExpandoObject();
in tryJsil produces the following:

Unhandled exception: TypeError: Cannot read property 'ExpandoObject' of undefined

Also, what type can I use on the C# side for dynamic objects such that the usage is completely erased by the compiler in favor of using native objects on the JS side?

For example, I'd want:

dynamic obj1 = new ExpandoOrWhatever()
dynamic obj2 = new ExpandoOrWhatever()
obj2.bar = 42;
obj1.foo = obj2;

to be compiled to:

obj1 = {}
obj2 = {}
obj2.bar = 42;
obj1.foo = obj1;
// obj1 = { foo: {bar: 42}}

thanks

@kg
Copy link
Member

kg commented Oct 3, 2016

I would suggest writing a small helper function that returns ExpandoObject in .NET and Verbatim.Expression("{}") in JS. There might actually be a simpler way to do this, but I forget. You can use Builtins.IsJavascript to do the branch, I think. The code might not be fully erased but it should work the way you want.

@D-R-R
Copy link

D-R-R commented Oct 4, 2016

The above example is working well for me in VS2013, but in VS2015, I end up with a much more verbose output using System.Runtime.CompilerServices.CallSite to invoke every operation in each expression. Searching reveals issue #531 where apparently the new Roslyn compiler creates issues with generating the concise output.

Is there a workaround or other technique to get the above result even with VS2015, or is that only available with the earlier version? Thank you in advance for your time.

@iskiselev
Copy link
Member

With latest version of JSIL translation of this sample should use all C#-dynamic mechanics, but should work with JS.
The only way to create clear JS from C# is to use Verbatium helpers.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants