sonygod / sharpkit

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

Constants should be inlined in the calling code #110

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In C#/.NET constants are inlined into the calling code instead of having a 
reference to the constant. It would be nice for SharpKit to do this as well for 
performance reasons.

Example code:

using SharpKit.JavaScript;
using SharpKit.Html4;
using SharpKit.jQuery;

namespace MyNamespace
{
    [JsType(JsMode.Clr)]
    public class MyClass
    {
        public const int MyConst = 10;

        public void MyMethod()
        {
            int x = MyConst;
        }
    }
}

Gets compiled to:

/*@Generated by SharpKit v4.23.4000*/
if(typeof(JsTypes) == "undefined")
    JsTypes = [];
var MyNamespace$MyClass=
{
    fullname:"MyNamespace.MyClass",
    baseTypeName:"System.Object",
    staticDefinition:{MyConst:10},
    assemblyName:"9c81f42b284046a88352d29b8daa12f5",
    Kind:"Class",
    definition:
    {
        ctor:function()
        {
            System.Object.ctor.call(this);
        },
        MyMethod:function()
        {
            var x=MyNamespace.MyClass.MyConst;
        }
    }
};
JsTypes.push(MyNamespace$MyClass);

It should be:

var x = 10

instead of var x = MyNamespace.MyClass.MyConst;

Original issue reported on code.google.com by warthog1...@gmail.com on 8 Mar 2012 at 5:46

GoogleCodeExporter commented 9 years ago
Supported in SharpKit 5

Original comment by DanelK...@gmail.com on 6 May 2012 at 1:59