Beispiel #1
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();
        }
Beispiel #2
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);
        }
Beispiel #3
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();
        }