Generic list as an array

91 views
Skip to first unread message

Ryan Fuller

unread,
Apr 22, 2013, 11:26:41 AM4/22/13
to shar...@googlegroups.com
I'm new to SharpKit and I'm stuck on something.

Is there any way to get a generic list to compile to a javascript array? I'm using Prototype mode and do not want to use CLR mode. I have a class that needs to run in both .Net and in the browser so I can't just use JsArray directly. Is this possible?

-Ryan

Dan-el Khen

unread,
Apr 22, 2013, 1:07:18 PM4/22/13
to shar...@googlegroups.com
Hi Ryan,

Yes it is possible, but you have to understand that JsArray<T> won't behave exactly like List<T> without clr mode. Anyway, if you got your heart set on it, I have created a special mode called NoClr mode, which means that you don't want to use clr mode and you wish that standard .net types will compile to the closest possible native js types. To use this mode, all you have to do is to add a reference to SharpKit.JavaScript.NoClr assembly. If you can't find it, you can simply download the source code from our SVN and compile it, you can also simply take the file and include it in your project directly:
Project is here:

The file itself is here:

As this mode is open-source, feel free to explore it / customize it anyway you want. You can see that this mode is simply a set a metadata instructions that map .NET types into JS types, as well as .NET methods that map into JS methods.

If you need any help with this, let me know!

Cheers
Dan-el





-Ryan

--
You received this message because you are subscribed to the Google Groups "SharpKit Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sharpkit+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ryan Fuller

unread,
Apr 25, 2013, 6:37:25 PM4/25/13
to shar...@googlegroups.com
This looks like it's almost what I need. However Count does not work.  I tried making it myself with [assembly: JsProperty(TargetTypeName = "System.Collections.Generic.List`1", TargetProperty = "Count", Name="length")]
 but it does not come out right (it's mapping Count to a call to get_length() instead of just the js array.length property). What am I missing?

-Ryan

Ryan Fuller

unread,
Apr 25, 2013, 6:41:30 PM4/25/13
to shar...@googlegroups.com
As is usual, I figured it out the second after I posted the question.  I ended up adding this to noclr.cs to get the Count property mapping to the js array length field.

[assembly: JsProperty(TargetTypeName = "System.Collections.Generic.List`1", TargetProperty = "Count", NativeField=true, Name="length")]

-Ryan

Dan-el Khen

unread,
Apr 26, 2013, 8:58:12 AM4/26/13
to shar...@googlegroups.com
Hey Ryan,

I was sure I've added this attribute myself, but it seems that I didn't. In any case your solution is the correct one. Would you like to gain read/write access to our SVN and commit this change yourself? If not, I can commit it for you.

Cheers and thanks!
Dan-el

Ryan Fuller

unread,
Apr 26, 2013, 3:26:15 PM4/26/13
to shar...@googlegroups.com
You can go ahead and commit it.  Thanks again for all your help. Noclr.cs is working perfect for me as just a little bit of glue to make working with lists easy.
-Ryan

Dan-el Khen

unread,
Apr 28, 2013, 6:03:28 AM4/28/13
to shar...@googlegroups.com
Done, thanks!

Dan-el
Reply all
Reply to author
Forward
0 new messages