Example #1
0
        protected virtual void EmitFields(TypeConfigInfo info)
        {
            if (info.Fields.Count > 0)
            {
                foreach (var field in info.Fields)
                {
                    if (field.Entity.HasModifier(Modifiers.Public))
                    {
                        this.Write(field.GetName(this.Emitter));
                        this.WriteColon();
                        string typeName = BridgeTypes.ToJsName(field.Entity.ReturnType, this.Emitter);
                        typeName = EmitBlock.HandleType(typeName);
                        this.Write(typeName);
                        this.WriteSemiColon();
                        this.WriteNewLine();
                    }
                }
            }

            if (info.Events.Count > 0)
            {
                foreach (var ev in info.Events)
                {
                    if (ev.Entity.HasModifier(Modifiers.Public))
                    {
                        var name = ev.GetName(this.Emitter);
                        if (name.StartsWith("$"))
                        {
                            name = name.Substring(1);
                        }

                        this.WriteEvent(ev, "add" + name);
                        this.WriteEvent(ev, "remove" + name);
                    }
                }
            }

            if (info.Properties.Count > 0)
            {
                foreach (var prop in info.Properties)
                {
                    if (prop.Entity.HasModifier(Modifiers.Public))
                    {
                        var name = prop.GetName(this.Emitter);
                        if (name.StartsWith("$"))
                        {
                            name = name.Substring(1);
                        }

                        this.WriteProp(prop, name, true);
                        this.WriteProp(prop, name, false);
                    }
                }
            }

            new MethodsBlock(this.Emitter, this.TypeInfo, this.StaticBlock).Emit();
        }
Example #2
0
        protected virtual void EmitFields(TypeConfigInfo info)
        {
            if (this.FieldsOnly)
            {
                if (info.Fields.Count > 0)
                {
                    var hasProperties = this.WriteObject(null, info.Fields, "this.{0} = {1};");
                    if (hasProperties)
                    {
                        this.Emitter.Comma = true;
                        this.WasEmitted = true;
                    }
                }
                return;
            }

            if (info.Events.Count > 0)
            {
                var hasProperties = this.WriteObject("events", info.Events, "Bridge.event(this, \"{0}\", {1});");
                if (hasProperties)
                {
                    this.Emitter.Comma = true;
                    this.WasEmitted = true;
                }
            }

            if (info.Properties.Count > 0)
            {
                var hasProperties = this.WriteObject("properties", info.Properties, "Bridge.property(this, \"{0}\", {1});");
                if (hasProperties)
                {
                    this.Emitter.Comma = true;
                    this.WasEmitted = true;
                }
            }

            if (info.Alias.Count > 0)
            {
                this.WriteAlias("alias", info.Alias);
                this.Emitter.Comma = true;
            }
        }
Example #3
0
        protected virtual void EmitFields(TypeConfigInfo info)
        {
            if (this.FieldsOnly)
            {
                if (info.Fields.Count > 0)
                {
                    this.WriteObject(null, info.Fields.Where(i => !i.IsConst).ToList(), (m, v) => string.Format("this.{0} = {1}", m.GetName(this.Emitter), v), FieldTypeEnum.Field);
                }
                return;
            }

            if (info.Events.Count > 0)
            {
                this.Indent();
                this.WriteObject(null, info.Events, (m, v) => {
                    string name = m.GetName(this.Emitter);
                    bool isPrivate = m.Entity.HasModifier(Modifiers.Private);
                    TransformCtx.CurClassOtherMethodNames.Add(new TransformCtx.MethodInfo() { Name = "add" + name, IsPrivate = isPrivate });
                    TransformCtx.CurClassOtherMethodNames.Add(new TransformCtx.MethodInfo() { Name = "remove" + name, IsPrivate = isPrivate });
                    return string.Format("add{0}, remove{0} = System.event(this, \"{0}\", {1})", name, v);
                }, FieldTypeEnum.Event);
                this.Outdent();
            }

            if (info.Properties.Count > 0)
            {
                this.WriteObject(null, info.Properties, (m, v) => {
                    string name = m.GetName(this.Emitter);
                    bool isPrivate = m.Entity.HasModifier(Modifiers.Private);
                    TransformCtx.CurClassOtherMethodNames.Add(new TransformCtx.MethodInfo() { Name = "get" + name, IsPrivate = isPrivate });
                    TransformCtx.CurClassOtherMethodNames.Add(new TransformCtx.MethodInfo() { Name = "set" + name, IsPrivate = isPrivate });
                    return string.Format("get{0}, set{0} = System.property(this, \"{0}\", {1})", name, v);
                }, FieldTypeEnum.Property);
            }

            if (info.Alias.Count > 0)
            {
                throw new System.NotSupportedException("Alias is not exists");
            }
        }