/// <summary>
        /// Decreases indentation by one level.
        /// </summary>
        internal void DecreaseIndentation(IndentationLevelScope indentationScope)
        {
            if (indentationScope == null)
            {
                throw new ArgumentNullException();
            }

            if (this.IndentationLevels <= 0)
            {
                throw new InvalidOperationException("Indentation level is already set to zero.");
            }

            this.IndentationLevels -= 1;
        }
Exemplo n.º 2
0
        protected virtual void AppendModule(TsModule module, ScriptBuilder sb, TsGeneratorOutput generatorOutput)
        {
            var classes = module.Classes.Where(c => !_typeConvertors.IsConvertorRegistered(c.Type) && !c.IsIgnored).ToList();
            var enums   = module.Enums.Where(e => !_typeConvertors.IsConvertorRegistered(e.Type) && !e.IsIgnored).ToList();

            if ((generatorOutput == TsGeneratorOutput.Enums && enums.Count == 0) ||
                (generatorOutput == TsGeneratorOutput.Properties && classes.Count == 0) ||
                (enums.Count == 0 && classes.Count == 0))
            {
                return;
            }

            var moduleName           = GetModuleName(module);
            var generateModuleHeader = moduleName != string.Empty;
            IndentationLevelScope indentationLevelScope = null;

            if (generateModuleHeader)
            {
                if (generatorOutput != TsGeneratorOutput.Enums &&
                    (generatorOutput & TsGeneratorOutput.Constants) != TsGeneratorOutput.Constants)
                {
                    sb.Append("declare ");
                }

                sb.AppendLine(string.Format("module {0} {{", moduleName));

                indentationLevelScope = sb.IncreaseIndentation();
            }

            if ((generatorOutput & TsGeneratorOutput.Enums) == TsGeneratorOutput.Enums)
            {
                foreach (var enumModel in enums)
                {
                    this.AppendEnumDefinition(enumModel, sb, generatorOutput);
                }
            }

            if (((generatorOutput & TsGeneratorOutput.Properties) == TsGeneratorOutput.Properties) ||
                (generatorOutput & TsGeneratorOutput.Fields) == TsGeneratorOutput.Fields)
            {
                foreach (var classModel in classes)
                {
                    this.AppendClassDefinition(classModel, sb, generatorOutput);
                }
            }

            if ((generatorOutput & TsGeneratorOutput.Constants) == TsGeneratorOutput.Constants)
            {
                foreach (var classModel in classes)
                {
                    if (classModel.IsIgnored)
                    {
                        continue;
                    }

                    this.AppendConstantModule(classModel, sb);
                }
            }
            if (generateModuleHeader)
            {
                sb.DecreaseIndentation(indentationLevelScope);
                sb.AppendLine("}");
            }
        }
        /// <summary>
        /// Decreases indentation by one level.
        /// </summary>
        internal void DecreaseIndentation(IndentationLevelScope indentationScope)
        {
            if (indentationScope == null) {
                throw new ArgumentNullException();
            }

            if (this.IndentationLevels <= 0) {
                throw new InvalidOperationException("Indentation level is already set to zero.");
            }

            this.IndentationLevels -= 1;
        }