kjm00king / sharpkit

Automatically exported from code.google.com/p/sharpkit
0 stars 0 forks source link

Initialising List<int> from int[] #309

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Attempting to initialise a list from an array fails at run time.

    [JsType(JsMode.Clr, Filename = "res/Init.js")]
    public static class Init
    {
        public static void createList()
        {
            var numbers = new[] { 4, 5, 6};
            var aList = new List<int>(numbers);
            new jQuery(HtmlContext.document.body).append(aList.ToString());
        }
    }

    [JsType(JsMode.Global, Filename = "res/Default.js")]
    public class DefaultClient
    {
        static void DefaultClient_Load()
        {
            new jQuery(HtmlContext.document.body).append("Ready<br/>");
        }
        static void btnTest_click(DOMEvent e)
        {
            Init.createList();
        }
    }

The issue is that GetEnumerator is missing

Uncaught TypeError: Object #<Int32Array> has no method 'GetEnumerator' 
jsclr.js:6861
System$Collections$Generic$List$1.definition.AddRange jsclr.js:6861
System$Collections$Generic$List$1.definition.ctor$$IEnumerable$1 jsclr.js:6819
SharpKitWebApp1$Init.staticDefinition.createList Init.js:15
btnTest_click Default.js:8
onclick

/*Generated by SharpKit 5 v5.2.0*/

You can workaround it by copying the type initialisation from the array e.g.

JsTypes.push({
    fullname: "Int32Array",
    definition:
    {
        GetEnumerator: function () {
            return new ArrayEnumerator.ctor(this);
        }
    }
});

Original issue reported on code.google.com by co...@gravill.com on 7 Aug 2013 at 12:44

GoogleCodeExporter commented 8 years ago
This is fixed in issue 311.

Original comment by sebastia...@gmail.com on 4 Nov 2013 at 6:20