thanhhovn / sharpkit

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

Typed arrays with out parameters #310

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Using methods with out parameters on typed arrays fail. The issue is that the 
intermediate object structure gets coerced to the type of the array.

    [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.tryWithArray();
        }
    }

        //Example method
        public static void TryParse(string text, out int target)
        {
            if (text == "1")
            {
                target = 1;
            }
            else
            {
                target = -1;
            }
        }

        public static void tryWithArray()
        {
            var output = new int[1];
            output[0] = 7;
            TryParse("1", out output[0]);

            new jQuery(HtmlContext.document.body).append(output[0]);
        }

You can see the problem in the JavaScript:

        tryWithArray: function ()
        {
            var output = new Int32Array(1);
            output[0] = 7;
            (function ()
            {
                output[0] = {Value: output[0]};
                var $res = SharpKitWebApp1.Init.TryParse("1", output[0]);
                output[0] = output[0].Value;
                return $res;
            })();
            $(document.body).append(output[0]);
        }

Specifically the line: output[0] = {Value: output[0]};

/*Generated by SharpKit 5 v5.2.0*/

Original issue reported on code.google.com by co...@gravill.com on 8 Aug 2013 at 9:48

GoogleCodeExporter commented 8 years ago

Original comment by sebastia...@gmail.com on 1 Nov 2013 at 3:01

GoogleCodeExporter commented 8 years ago

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

GoogleCodeExporter commented 8 years ago

Original comment by DanelK...@gmail.com on 5 Nov 2013 at 1:08