From 909f4c35b8731b48f6ecce7957216c4a6914ffa8 Mon Sep 17 00:00:00 2001 From: Alex Friedman Date: Wed, 5 Apr 2017 01:33:12 -0400 Subject: [PATCH] Add ability to make all properties camel case --- Src/TypeScripter/Scripter.cs | 9 +++++++++ Src/TypeScripter/TypeScript/TsFormatter.cs | 20 +++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Src/TypeScripter/Scripter.cs b/Src/TypeScripter/Scripter.cs index adb8b71..707a26e 100644 --- a/Src/TypeScripter/Scripter.cs +++ b/Src/TypeScripter/Scripter.cs @@ -265,6 +265,15 @@ public Scripter UsingTypeFilter(Func filter) this.TypeFilter = filter; return this; } + + /// + /// Use lower camel case for properties + /// + public Scripter LowerCamelCaseProperties() + { + this.Formatter.LowerCamelCaseProperties = true; + return this; + } #endregion #region Type Generation diff --git a/Src/TypeScripter/TypeScript/TsFormatter.cs b/Src/TypeScripter/TypeScript/TsFormatter.cs index 5c5c5c6..dd96353 100644 --- a/Src/TypeScripter/TypeScript/TsFormatter.cs +++ b/Src/TypeScripter/TypeScript/TsFormatter.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -105,6 +106,14 @@ public bool EnumsAsString { get; set; } + + /// + /// Use lower camel case for properties + /// + public bool LowerCamelCaseProperties + { + get; set; + } #endregion #region Creation @@ -221,11 +230,16 @@ public virtual string Format(TsProperty property) { using (var sbc = new StringBuilderContext(this)) { - this.Write("{0}{1}: {2};", Format(property.Name), property.Optional?"?":"", Format(property.Type)); - return sbc.ToString(); + this.Write("{0}{1}: {2};", Format(property.Name), property.Optional ? "?" : "", Format(property.Type)); + var result = sbc.ToString(); + if (!LowerCamelCaseProperties) + { + return result; + } + return char.ToLower(result[0]) + (result.Length == 1 ? String.Empty : result.Substring(1)); } } - + /// /// Formats an indexer property ///