示例#1
0
        private void GenereateHashCode(IAnonymousTypeConfig config)
        {
            this.EnsureComma();
            this.Write("getHashCode: function () ");
            this.BeginBlock();
            this.Write("var hash = 17;");

            this.WriteNewLine();
            this.Write("hash = hash * 23 + " + config.Name.GetHashCode() + ";");

            foreach (var property in config.Type.Properties)
            {
                var name = Object.Net.Utilities.StringUtils.ToLowerCamelCase(property.Name);

                this.WriteNewLine();
                this.Write("hash = hash * 23 + ");
                this.Write("(this." + name);
                this.Write(" == null ? 0 : ");
                this.Write("Bridge.getHashCode(");
                this.Write("this." + name);
                this.Write("));");
            }

            this.WriteNewLine();
            this.Write("return hash;");
            this.WriteNewLine();
            this.EndBlock();
            this.Emitter.Comma = true;
        }
        protected void VisitAnonymousTypeCreateExpression()
        {
            AnonymousTypeCreateExpression anonymousTypeCreateExpression = this.AnonymousTypeCreateExpression;
            var invocationrr            = this.Emitter.Resolver.ResolveNode(anonymousTypeCreateExpression, this.Emitter) as InvocationResolveResult;
            var type                    = invocationrr.Type as AnonymousType;
            IAnonymousTypeConfig config = null;

            if (!this.Emitter.AnonymousTypes.ContainsKey(type))
            {
                config = CreateAnonymousType(type);
                this.Emitter.AnonymousTypes.Add(type, config);
            }
            else
            {
                config = this.Emitter.AnonymousTypes[type];
            }

            this.WriteNew();
            this.Write(config.Name);
            this.WriteOpenParentheses();

            if (anonymousTypeCreateExpression.Initializers.Count > 0)
            {
                this.WriteObjectInitializer(anonymousTypeCreateExpression.Initializers, true, true);
            }

            this.WriteCloseParentheses();
        }
        private void GenerateHashCode(IAnonymousTypeConfig config)
        {
            this.EnsureComma();
            this.Write(JS.Funcs.GETHASHCODE + ": function () ");
            this.BeginBlock();
            this.Write("var h = " + JS.Funcs.BRIDGE_ADDHASH + "([");

            var nameHashValue = new HashHelper().GetDeterministicHash(config.Name);

            this.Write(nameHashValue);

            foreach (var property in config.Type.Properties)
            {
                var name = this.Emitter.GetEntityName(property);
                this.Write(", this." + name);
            }

            this.Write("]);");

            this.WriteNewLine();
            this.Write("return h;");
            this.WriteNewLine();
            this.EndBlock();
            this.Emitter.Comma = true;
        }
示例#4
0
        private void GenerateHashCode(IAnonymousTypeConfig config)
        {
            this.EnsureComma();
            this.Write(JS.Funcs.GETHASHCODE + ": function () ");
            this.BeginBlock();
            this.Write("var hash = 17;");

            this.WriteNewLine();

            var nameHashValue = new HashHelper().GetDeterministicHash(config.Name);

            this.Write("hash = hash * 23" + nameHashValue + ";");

            foreach (var property in config.Type.Properties)
            {
                var name = Object.Net.Utilities.StringUtils.ToLowerCamelCase(property.Name);

                this.WriteNewLine();
                this.Write("hash = hash * 23 + ");
                this.Write("(this." + name);
                this.Write(" == null ? 0 : ");
                this.Write(JS.Funcs.BRIDGE_GETHASHCODE + "(");
                this.Write("this." + name);
                this.Write("));");
            }

            this.WriteNewLine();
            this.Write("return hash;");
            this.WriteNewLine();
            this.EndBlock();
            this.Emitter.Comma = true;
        }
        private void GenereateMetadata(IAnonymousTypeConfig config)
        {
            var meta = MetadataUtils.ConstructITypeMetadata(config.Type, this.Emitter);

            if (meta != null)
            {
                this.EnsureComma();
                this.Write("statics : ");
                this.BeginBlock();
                this.Write("$metadata : ");
                this.Write(meta.ToString(Formatting.None));
                this.WriteNewLine();
                this.EndBlock();
            }
        }
        private void GenereateGetters(IAnonymousTypeConfig config)
        {
            foreach (var property in config.Type.Properties)
            {
                this.EnsureComma();
                var lowerName = Object.Net.Utilities.StringUtils.ToLowerCamelCase(property.Name);
                var name      = property.Name;

                this.Write(string.Format("get{0} : function () ", name));
                this.BeginBlock();
                this.Write(string.Format("return this.{0};", lowerName));
                this.WriteNewLine();
                this.EndBlock();
                this.Emitter.Comma = true;
            }
        }
        private void GenereateEquals(IAnonymousTypeConfig config)
        {
            this.EnsureComma();
            this.Write(JS.Funcs.EQUALS + ": function (o) ");
            this.BeginBlock();

            this.Write("if (!" + JS.Types.Bridge.IS + "(o, ");
            this.Write(config.Name);
            this.Write(")) ");
            this.BeginBlock();
            this.Write("return false;");
            this.WriteNewLine();
            this.EndBlock();
            this.WriteNewLine();
            this.Write("return ");

            bool and = false;

            foreach (var property in config.Type.Properties)
            {
                var name = this.Emitter.GetEntityName(property);

                if (and)
                {
                    this.Write(" && ");
                }

                and = true;

                this.Write(JS.Funcs.BRIDGE_EQUALS + "(this.");
                this.Write(name);
                this.Write(", o.");
                this.Write(name);
                this.Write(")");
            }

            this.Write(";");

            this.WriteNewLine();
            this.EndBlock();
            this.Emitter.Comma = true;
        }
        private void GenereateEquals(IAnonymousTypeConfig config)
        {
            this.EnsureComma();
            this.Write(JS.Funcs.EQUALS + ": function (o) ");
            this.BeginBlock();

            this.Write("if (!" + JS.Funcs.BRIDGE_IS + "(o, ");
            this.Write(config.Name);
            this.Write(")) ");
            this.BeginBlock();
            this.Write("return false;");
            this.WriteNewLine();
            this.EndBlock();
            this.WriteNewLine();
            this.Write("return ");

            bool and = false;

            foreach (var property in config.Type.Properties)
            {
                var name = Object.Net.Utilities.StringUtils.ToLowerCamelCase(property.Name);

                if (and)
                {
                    this.Write(" && ");
                }

                and = true;

                this.Write(JS.Funcs.BRIDGE_EQUALS + "(this.");
                this.Write(name);
                this.Write(", o.");
                this.Write(name);
                this.Write(")");
            }

            this.Write(";");

            this.WriteNewLine();
            this.EndBlock();
            this.Emitter.Comma = true;
        }
示例#9
0
        private void GenereateMetadata(IAnonymousTypeConfig config)
        {
            var meta = MetadataUtils.ConstructITypeMetadata(config.Type, Emitter);

            if (meta != null)
            {
                EnsureComma();
                Write("statics : ");
                BeginBlock();

                Write(JS.Fields.METHODS);
                WriteColon();
                BeginBlock();

                Write("$metadata : function () { return ");
                Write(meta.ToString(Formatting.None));
                Write("; }");
                WriteNewLine();
                EndBlock();
                WriteNewLine();
                EndBlock();
            }
        }
示例#10
0
        private void GenereateToJSON(IAnonymousTypeConfig config)
        {
            this.EnsureComma();
            this.Write(JS.Funcs.TOJSON + ": function () ");
            this.BeginBlock();
            this.Write("return ");
            this.BeginBlock();

            foreach (var property in config.Type.Properties)
            {
                this.EnsureComma();
                var name = this.Emitter.GetEntityName(property);

                this.Write(string.Format("{0} : this.{0}", name));
                this.Emitter.Comma = true;
            }

            this.WriteNewLine();
            this.EndBlock();
            this.WriteSemiColon();
            this.WriteNewLine();
            this.EndBlock();
            this.Emitter.Comma = true;
        }
        private void GenereateToJSON(IAnonymousTypeConfig config)
        {
            this.EnsureComma();
            this.Write(JS.Funcs.TOJSON + ": function () ");
            this.BeginBlock();
            this.Write("return ");
            this.BeginBlock();

            foreach (var property in config.Type.Properties)
            {
                this.EnsureComma();
                var name = Object.Net.Utilities.StringUtils.ToLowerCamelCase(property.Name);

                this.Write(string.Format("{0} : this.{0}", name));
                this.Emitter.Comma = true;
            }

            this.WriteNewLine();
            this.EndBlock();
            this.WriteSemiColon();
            this.WriteNewLine();
            this.EndBlock();
            this.Emitter.Comma = true;
        }