Exemplo n.º 1
0
        private void WriteEvent(TypeConfigItem ev, string name, bool adder)
        {
            XmlToJsDoc.EmitComment(this, ev.Entity, adder);
            Write(name);
            WriteOpenParentheses();
            Write("value");
            WriteColon();
            string typeName = H5Types.ToTypeScriptName(ev.Entity.ReturnType, Emitter);

            Write(typeName);

            var resolveResult = Emitter.Resolver.ResolveNode(ev.Entity.ReturnType);

            if (resolveResult != null && (resolveResult.Type.IsReferenceType.HasValue && resolveResult.Type.IsReferenceType.Value || resolveResult.Type.IsKnownType(KnownTypeCode.NullableOfT)))
            {
                Write(" | null");
            }

            WriteCloseParentheses();
            WriteColon();
            Write("void");

            WriteSemiColon();
            WriteNewLine();
        }
Exemplo n.º 2
0
        public static string GetEnumItemName(IEmitter emitter, TypeConfigItem field)
        {
            var memeber_rr = (MemberResolveResult)emitter.Resolver.ResolveNode(field.Entity);
            var mname      = emitter.GetEntityName(memeber_rr.Member);

            return(mname);
        }
Exemplo n.º 3
0
        private void WriteProp(TypeConfigItem ev, string name, bool getter)
        {
            XmlToJsDoc.EmitComment(this, ev.Entity, getter);
            this.Write(Helpers.GetSetOrGet(!getter));
            this.Write(name);
            this.WriteOpenParentheses();

            if (!getter)
            {
                this.Write("value");
                this.WriteColon();
                string typeName = BridgeTypes.ToTypeScriptName(ev.Entity.ReturnType, this.Emitter);
                this.Write(typeName);
            }

            this.WriteCloseParentheses();
            this.WriteColon();

            if (!getter)
            {
                this.Write("void");
            }
            else
            {
                string typeName = BridgeTypes.ToTypeScriptName(ev.Entity.ReturnType, this.Emitter);
                this.Write(typeName);
            }

            this.WriteSemiColon();
            this.WriteNewLine();
        }
Exemplo n.º 4
0
        private void WriteProp(TypeConfigItem ev, string name, bool getter)
        {
            this.Write(getter ? "get" : "set");
            this.Write(name);
            this.WriteOpenParentheses();

            if (!getter)
            {
                this.Write("value");
                this.WriteColon();
                string typeName = BridgeTypes.ToJsName(ev.Entity.ReturnType, this.Emitter);
                typeName = EmitBlock.HandleType(typeName);
                this.Write(typeName);
            }

            this.WriteCloseParentheses();
            this.WriteColon();

            if (!getter)
            {
                this.Write("void");
            }
            else
            {
                string typeName = BridgeTypes.ToJsName(ev.Entity.ReturnType, this.Emitter);
                typeName = EmitBlock.HandleType(typeName);
                this.Write(typeName);
            }

            this.WriteSemiColon();
            this.WriteNewLine();
        }
Exemplo n.º 5
0
        private void CheckInterfacePeoperty(ITypeInfo type, DefaultResolvedProperty property)
        {
            if (!type.InstanceProperties.ContainsKey(property.Name))
            {
                foreach (IType baseClass in type.Type.GetAllBaseTypes())
                {
                    if (baseClass.Kind == TypeKind.Class)
                    {
                        BridgeType baseBridgeType = BridgeTypes.Get(baseClass);
                        ITypeInfo  baseTypeInfo   = baseBridgeType.TypeInfo;
                        if (baseTypeInfo != null)
                        {
                            if (baseTypeInfo.InstanceProperties.ContainsKey(property.Name))
                            {
                                var instanceConfig = baseTypeInfo.InstanceConfig;
                                int fieldIndex     = instanceConfig.Fields.FindIndex(i => i.Name == property.Name);
                                if (fieldIndex != -1)
                                {
                                    if (!instanceConfig.Properties.Exists(i => i.Name == property.Name))
                                    {
                                        TypeConfigItem item = instanceConfig.Fields[fieldIndex];
                                        instanceConfig.Properties.Add(item);
                                        instanceConfig.Fields.RemoveAt(fieldIndex);

                                        TypeDefinition     typeDefinition     = baseBridgeType.TypeDefinition;
                                        PropertyDefinition propertyDefinition = typeDefinition.Properties.First(i => i.Name == property.Name);
                                        Helpers.SetCacheOfAutoPropertyOfDefinition(propertyDefinition);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void WriteProp(TypeConfigItem ev, string name)
        {
            XmlToJsDoc.EmitComment(this, ev.Entity);
            this.Write(name);
            this.WriteColon();

            string typeName = BridgeTypes.ToTypeScriptName(ev.Entity.ReturnType, this.Emitter);

            this.Write(typeName);

            this.WriteSemiColon();
            this.WriteNewLine();
        }
Exemplo n.º 7
0
        private void WriteEvent(TypeConfigItem ev, string name, bool adder)
        {
            XmlToJsDoc.EmitComment(this, ev.Entity, adder);
            this.Write(name);
            this.WriteOpenParentheses();
            this.Write("value");
            this.WriteColon();
            string typeName = BridgeTypes.ToTypeScriptName(ev.Entity.ReturnType, this.Emitter);

            this.Write(typeName);
            this.WriteCloseParentheses();
            this.WriteColon();
            this.Write("void");

            this.WriteSemiColon();
            this.WriteNewLine();
        }
Exemplo n.º 8
0
        private void WriteEvent(TypeConfigItem ev, string name)
        {
            this.Write(name);
            this.WriteOpenParentheses();
            this.Write("value");
            this.WriteColon();
            string typeName = BridgeTypes.ToJsName(ev.Entity.ReturnType, this.Emitter);

            typeName = EmitBlock.HandleType(typeName);
            this.Write(typeName);
            this.WriteCloseParentheses();
            this.WriteColon();
            this.Write("void");

            this.WriteSemiColon();
            this.WriteNewLine();
        }
Exemplo n.º 9
0
        private void WriteFieldDeclaration(TypeConfigItem field, VariableInitializer variableInitializer)
        {
            XmlToJsDoc.EmitComment(this, field.Entity, null, variableInitializer);

            if (TypeInfo.IsEnum)
            {
                Write(EnumBlock.GetEnumItemName(Emitter, field));
            }
            else
            {
                Write(field.GetName(Emitter));
            }

            if (field.VarInitializer != null)
            {
                var field_rr = Emitter.Resolver.ResolveNode(field.VarInitializer);
                if (field_rr is MemberResolveResult mrr && mrr.Member.Attributes.Any(a => a.AttributeType.FullName == "H5.OptionalAttribute"))
                {
                    Write("?");
                }
            }

            WriteColon();

            string typeName = TypeInfo.IsEnum
                ? (Helpers.IsStringNameEnum(TypeInfo.Type) ? "string" : "number")
                : H5Types.ToTypeScriptName(field.Entity.ReturnType, Emitter);

            Write(typeName);

            if (!TypeInfo.IsEnum)
            {
                var resolveResult = Emitter.Resolver.ResolveNode(field.Entity.ReturnType);
                if (resolveResult != null && (resolveResult.Type.IsReferenceType.HasValue && resolveResult.Type.IsReferenceType.Value || resolveResult.Type.IsKnownType(KnownTypeCode.NullableOfT)))
                {
                    Write(" | null");
                }
            }

            WriteSemiColon();
            WriteNewLine();
        }
Exemplo n.º 10
0
        private void WriteProp(TypeConfigItem ev, string name)
        {
            XmlToJsDoc.EmitComment(this, ev.Entity);
            this.Write(name);
            this.WriteColon();

            string typeName = BridgeTypes.ToTypeScriptName(ev.Entity.ReturnType, this.Emitter);

            this.Write(typeName);

            var resolveResult = this.Emitter.Resolver.ResolveNode(ev.Entity.ReturnType, this.Emitter);

            if (resolveResult != null && (resolveResult.Type.IsReferenceType.HasValue && resolveResult.Type.IsReferenceType.Value || resolveResult.Type.IsKnownType(KnownTypeCode.NullableOfT)))
            {
                this.Write(" | null");
            }

            this.WriteSemiColon();
            this.WriteNewLine();
        }
Exemplo n.º 11
0
        public static string GetEnumItemName(IEmitter emitter, TypeConfigItem field)
        {
            var memeber_rr = (MemberResolveResult)emitter.Resolver.ResolveNode(field.Entity, emitter);
            var mode       = emitter.Validator.EnumEmitMode(memeber_rr.Member.DeclaringTypeDefinition);
            var mname      = field.GetName(emitter, true);

            var attr = Helpers.GetInheritedAttribute(memeber_rr.Member, Translator.Bridge_ASSEMBLY + ".NameAttribute");

            if (attr != null)
            {
                mname = emitter.GetEntityName(memeber_rr.Member);
            }
            else if (mode >= 3 && mode < 7)
            {
                switch (mode)
                {
                case 3:
                    mname = Object.Net.Utilities.StringUtils.ToLowerCamelCase(memeber_rr.Member.Name);
                    break;

                case 4:
                    mname = memeber_rr.Member.Name;
                    break;

                case 5:
                    mname = memeber_rr.Member.Name.ToLowerInvariant();
                    break;

                case 6:
                    mname = memeber_rr.Member.Name.ToUpperInvariant();
                    break;
                }
            }
            else if (mode < 3 && mode != 1)
            {
                mname = field.Name;
            }
            return(mname);
        }
Exemplo n.º 12
0
        private void WriteFieldDeclaration(TypeConfigItem field, VariableInitializer variableInitializer)
        {
            XmlToJsDoc.EmitComment(this, field.Entity, null, variableInitializer);

            if (this.TypeInfo.IsEnum)
            {
                this.Write(EnumBlock.GetEnumItemName(this.Emitter, field));
            }
            else
            {
                this.Write(field.GetName(this.Emitter));
            }

            this.WriteColon();

            string typeName = this.TypeInfo.IsEnum
                ? (this.Emitter.Validator.IsStringNameEnum(this.TypeInfo.Type) ? "string" : "number")
                : BridgeTypes.ToTypeScriptName(field.Entity.ReturnType, this.Emitter);

            this.Write(typeName);
            this.WriteSemiColon();
            this.WriteNewLine();
        }