Beispiel #1
0
        public string Generate(bool emitEnumType)
        {
            TSBuilder builder = new TSBuilder();

            builder.DocumentationComment(comment =>
            {
                comment.Description($"Defines values for {Name}.");
                comment.Description(ExtendedDocumentation);
                comment.ReadOnly();
                comment.Enum(CodeNamer.Instance.CamelCase(UnderlyingType.Name));
            });

            if (emitEnumType)
            {
                builder.ExportEnum(Name, tsEnum =>
                {
                    foreach (EnumValue value in Values)
                    {
                        tsEnum.DocumentationComment(value.Description);
                        string valueName  = CodeNamer.Instance.GetEnumMemberName(value.MemberName);
                        string valueValue = CodeNamerTS.GetEnumValueName(value.SerializedName, UnderlyingType);
                        if (valueValue == null || valueValue == "null")
                        {
                            valueValue = "\"null\"";
                        }
                        tsEnum.Value(valueName, valueValue);
                    }
                });
            }
            else
            {
                builder.ExportUnionType(Name, Values.Select(v => CodeNamerTS.GetEnumValueName(v.SerializedName, UnderlyingType)));
            }

            return(builder.ToString());
        }