Пример #1
0
        protected virtual void AppendEnumDefinition(TsEnum enumModel, ScriptBuilder sb, TsGeneratorOutput output)
        {
            string typeName   = this.GetTypeName(enumModel);
            string visibility = (output & TsGeneratorOutput.Enums) == TsGeneratorOutput.Enums || (output & TsGeneratorOutput.Constants) == TsGeneratorOutput.Constants ? "export " : "";

            _docAppender.AppendEnumDoc(sb, enumModel, typeName);

            string constSpecifier = this.GenerateConstEnums ? "const " : string.Empty;

            sb.AppendLineIndented(string.Format("{0}{2}enum {1} {{", visibility, typeName, constSpecifier));

            using (sb.IncreaseIndentation()) {
                int i = 1;
                foreach (var v in enumModel.Values)
                {
                    _docAppender.AppendEnumValueDoc(sb, v);
                    sb.AppendLineIndented(string.Format(i < enumModel.Values.Count ? "{0} = {1}," : "{0} = {1}", v.Name, v.Value));
                    i++;
                }
            }

            sb.AppendLineIndented("}");

            _generatedEnums.Add(enumModel);
        }
        protected virtual void AppendEnumDefinition(TsEnum enumModel, IndentedStringBuilder sb, TsGeneratorOutput output)
        {
            var typeName   = GetTypeName(enumModel);
            var visibility = (output & TsGeneratorOutput.Enums) == TsGeneratorOutput.Enums || (output & TsGeneratorOutput.Constants) == TsGeneratorOutput.Constants ? "export " : "";

            DocAppender.AppendEnumDoc(sb, enumModel, typeName);

            var constSpecifier = Options.GenerateConstEnums ? "const " : string.Empty;

            sb.AppendLine(string.Format("{0}{2}enum {1} {{", visibility, typeName, constSpecifier));

            using (sb.Indent())
            {
                var i = 1;
                foreach (var v in enumModel.Values)
                {
                    DocAppender.AppendEnumValueDoc(sb, v);
                    sb.AppendLine(string.Format(i < enumModel.Values.Count ? "{0} = {1}," : "{0} = {1}", v.Name, v.Value));
                    i++;
                }
            }

            sb.AppendLine("}");

            GeneratedEnums.Add(enumModel);
        }
Пример #3
0
        protected virtual void AppendEnumDefinition(TsEnum enumModel, ScriptBuilder sb, TsGeneratorOutput output)
        {
            string typeName   = this.GetTypeName(enumModel);
            string visibility = (output & TsGeneratorOutput.Enums) == TsGeneratorOutput.Enums || (output & TsGeneratorOutput.Constants) == TsGeneratorOutput.Constants ? "export " : "";

            _docAppender.AppendEnumDoc(sb, enumModel, typeName);

            string constSpecifier = this.GenerateConstEnums ? "const " : string.Empty;

            sb.AppendLineIndented(string.Format("{0}{2}enum {1} {{", visibility, typeName, constSpecifier));

            using (sb.IncreaseIndentation()) {
                int    i                = 1;
                string valuesList       = "";
                string descriptionsList = "";

                foreach (var v in enumModel.Values)
                {
                    _docAppender.AppendEnumValueDoc(sb, v);
                    bool appendComma = enumModel.IsOutputValuesList || enumModel.IsOutputDescriptionsList || (i < enumModel.Values.Count);
                    if (enumModel.IsValueAsStringOfName)
                    {
                        sb.AppendLineIndented(string.Format(appendComma ? "{0} = '{0}'," : "{0} = '{0}'", v.Name));
                        if (enumModel.IsOutputValuesList)
                        {
                            valuesList += string.Format((i < enumModel.Values.Count) ? "{0}|" : "{0}", v.Name);
                        }
                    }
                    else
                    {
                        sb.AppendLineIndented(string.Format(appendComma ? "{0} = {1}," : "{0} = {1}", v.Name, v.Value));
                        if (enumModel.IsOutputValuesList)
                        {
                            valuesList += string.Format(i < enumModel.Values.Count ? "{0}|" : "{0}", v.Value);
                        }
                    }
                    if (enumModel.IsOutputDescriptionsList)
                    {
                        descriptionsList += string.Format(i < enumModel.Values.Count ? "{0}|" : "{0}", v.Description);
                    }
                    i++;
                }
                if (enumModel.IsOutputValuesList)
                {
                    sb.AppendLineIndented(string.Format(enumModel.IsOutputDescriptionsList ? "_ValuesList = '{0}'," : "_ValuesList = '{0}'", valuesList));
                }
                if (enumModel.IsOutputDescriptionsList)
                {
                    sb.AppendLineIndented(string.Format("_DescriptionsList = '{0}'", descriptionsList));
                }
            }

            sb.AppendLineIndented("}");

            _generatedEnums.Add(enumModel);
        }