mgusmano / sharpkit

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

Is it possible to support parametric constructors on structs? #235

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I tried using a more complex struct with a constructor. It seems like the 
generated JavaScript uses the default constructor. Would it be possible to 
generate parametric constructors and use them on structs as is done for 
classes? For this example if I switch to class it works fine.

    [JsType(JsMode.Clr, Filename = "res/Square.js")]
    public struct Square
    {
        public int X;
        public int Y;
        public int Width;
        public int Height;

        public Square(int x, int y, int width, int height)
        {
            X = x;
            Y = y;
            Width = width;
            Height = height;
        }
    }

    [JsType(JsMode.Global, Filename = "res/Default.js")]
    public class DefaultClient : jQueryContextBase
    {
        static void btnTest_click(HtmlDomEventArgs e)
        {
            var square = new Square(3, 3, 10, 10);
            J(document.body).append(string.Format("X:{0}, Y:{1}", square.X, square.Y));
        }
    }

JS:

/*Generated by SharpKit 5 v4.30.0000*/
if (typeof(JsTypes) == "undefined")
    var JsTypes = [];
var SharpKitWebApp2$Square =
{
    fullname: "SharpKitWebApp2.Square",
    baseTypeName: "System.ValueType",
    assemblyName: "SharpKitWebApp2",
    Kind: "Struct",
    definition:
    {
        ctor: function ()
        {
            this.X = 0;
            this.Y = 0;
            this.Width = 0;
            this.Height = 0;
            System.ValueType.ctor.call(this);
        }
    }
};
JsTypes.push(SharpKitWebApp2$Square);

It outputs X:0, Y:0 instead of X:3, Y:3 which it outputs if I use a class 
instead.

SharpKit 5 Professional Edition v4.30.0000

Original issue reported on code.google.com by co...@gravill.com on 9 Oct 2012 at 3:41

GoogleCodeExporter commented 8 years ago
Shouldn't be a problem supporting this...

Original comment by DanelK...@gmail.com on 9 Oct 2012 at 3:55

GoogleCodeExporter commented 8 years ago

Original comment by DanelK...@gmail.com on 9 Oct 2012 at 3:55

GoogleCodeExporter commented 8 years ago

Original comment by sebastia...@gmail.com on 20 Oct 2012 at 10:07