/// <summary>
        /// Generates TypeScript definitions for classes and/or enums in the model.
        /// </summary>
        /// <param name="model">The code model with classes to generate definitions for.</param>
        /// <param name="generatorOutput">The type of definitions to generate</param>
        /// <returns>TypeScript definitions for classes and/or enums in the model..</returns>
        public string Generate(TsModel model, TsGeneratorOutput generatorOutput)
        {
            var sb = new ScriptBuilder(this.IndentationString);

            if ((generatorOutput & TsGeneratorOutput.Properties) == TsGeneratorOutput.Properties ||
                (generatorOutput & TsGeneratorOutput.Fields) == TsGeneratorOutput.Fields)
            {
                if ((generatorOutput & TsGeneratorOutput.Constants) == TsGeneratorOutput.Constants)
                {
                    // We can't generate constants together with properties or fields, because we can't set values in a .d.ts file.
                    throw new InvalidOperationException("Cannot generate constants together with properties or fields");
                }

                foreach (var reference in _references.Concat(model.References))
                {
                    this.AppendReference(reference, sb);
                }
                sb.AppendLine();
            }

            // We can't just sort by the module name, because a formatter can jump in and change it so
            // format by the desired target name
            foreach (var module in model.Modules.OrderBy(m => GetModuleName(m)))
            {
                this.AppendModule(module, sb, generatorOutput);
            }

            return(sb.ToString());
        }
        /// <summary>
        /// Generates TypeScript definitions for classes and/or enums in the model.
        /// </summary>
        /// <param name="model">The code model with classes to generate definitions for.</param>
        /// <param name="generatorOutput">The type of definitions to generate</param>
        /// <returns>TypeScript definitions for classes and/or enums in the model..</returns>
        public string Generate(TsModel model, TsGeneratorOutput generatorOutput)
        {
            var sb = new ScriptBuilder(this.IndentationString);

            if ((generatorOutput & TsGeneratorOutput.Properties) == TsGeneratorOutput.Properties ||
                (generatorOutput & TsGeneratorOutput.Fields) == TsGeneratorOutput.Fields)
            {
                if ((generatorOutput & TsGeneratorOutput.Constants) == TsGeneratorOutput.Constants)
                {
                    // We can't generate constants together with properties or fields, because we can't set values in a .d.ts file.
                    throw new InvalidOperationException("Cannot generate constants together with properties or fields");
                }

                foreach (var reference in _references.Concat(model.References))
                {
                    this.AppendReference(reference, sb);
                }
                sb.AppendLine();
            }

            foreach (var module in model.Modules)
            {
                this.AppendModule(module, sb, generatorOutput);
            }

            return(sb.ToString());
        }