polytronicgr / sharpkit

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

Typed array as IList and indexing #348

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
If you return a typed array from a general method as an IList then indexing 
will fail. The underlying typed array doesn't support the getter and setters 
that will be generated e.g.

        public static void ArraysAsIListT()
        {
            IList<int> ints = new[] {1, 2, 3};

            ints[0] = 4;
            var val = ints[2];

        }

generates

        ArraysAsIListT: function ()
        {
            var ints = new Int32Array([1, 2, 3]);
            ints.set_Item$$Int32(0, 4);
            var val = ints.get_Item$$Int32(2);
        }

Which errors with:

Uncaught TypeError: Object #<Int32Array> has no method 'set_Item$$Int32'

/* Generated by SharpKit 5 v5.3.4 */ 

Original issue reported on code.google.com by co...@gravill.com on 28 Jan 2014 at 5:58

GoogleCodeExporter commented 8 years ago
This code adds support for IList in native arrays:

    [JsType(JsMode.Prototype, Name="Array", OmitDefaultConstructor=true, NativeOverloads=false)]
    class JsArrayExtensions<T> : JsArray<T>
    {
        public T this[int index]
        {
            get { return this.As<JsArray<T>>()[index]; }
            set { this.As<JsArray<T>>()[index] = value; }
        }
    }

Original comment by DanelK...@gmail.com on 13 Mar 2014 at 5:59

GoogleCodeExporter commented 8 years ago

Original comment by DanelK...@gmail.com on 13 Mar 2014 at 6:32