示例#1
0
        /// <summary>
        /// Generates class definition and appends it to the output.
        /// </summary>
        /// <param name="classModel">The class to generate definition for.</param>
        /// <param name="sb">The output.</param>
        /// <param name="generatorOutput"></param>
        protected virtual void AppendConstantModule(TsClass classModel, ScriptBuilder sb)
        {
            if (!classModel.Constants.Any())
            {
                return;
            }

            string typeName = this.GetTypeName(classModel);

            sb.AppendLineIndented(string.Format("export namespace {0} {{", typeName));

            using (sb.IncreaseIndentation()) {
                foreach (var property in classModel.Constants)
                {
                    if (property.IsIgnored)
                    {
                        continue;
                    }

                    _docAppender.AppendConstantModuleDoc(sb, property, this.GetPropertyName(property), this.GetPropertyType(property));
                    sb.AppendFormatIndented("export const {0}: {1} = {2};", this.GetPropertyName(property), this.GetPropertyType(property), this.GetPropertyConstantValue(property));
                    sb.AppendLine();
                }
            }
            sb.AppendLineIndented("}");

            _generatedClasses.Add(classModel);
        }
        /// <summary>
        /// Generates class definition and appends it to the output.
        /// </summary>
        /// <param name="classModel">The class to generate definition for.</param>
        /// <param name="sb">The output.</param>
        protected virtual void AppendConstantModule(TsClass classModel, IndentedStringBuilder sb)
        {
            if (!classModel.Constants.Any())
            {
                return;
            }

            var typeName = GetTypeName(classModel);

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

            using (sb.Indent())
            {
                foreach (var property in classModel.Constants)
                {
                    if (property.IsIgnored)
                    {
                        continue;
                    }

                    DocAppender.AppendConstantModuleDoc(sb, property, GetPropertyName(property), GetPropertyType(property));
                    sb.Append(string.Format("export var {0}: {1} = {2};", GetPropertyName(property), GetPropertyType(property), GetPropertyConstantValue(property)));
                    sb.AppendLine();
                }
            }
            sb.AppendLine("}");

            GeneratedClasses.Add(classModel);
        }