Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 2a14912

Browse files
committed
Add support for creating config scopes using CamelCase Humps notation
1 parent fda969a commit 2a14912

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/ServiceStack.Text/JsConfig.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,109 +49,149 @@ public static JsConfigScope CreateScope(string config, JsConfigScope scope = nul
4949

5050
switch (key)
5151
{
52+
case "cotisd":
5253
case "convertobjecttypesintostringdictionary":
5354
scope.ConvertObjectTypesIntoStringDictionary = boolValue;
5455
break;
56+
case "ttpptv":
5557
case "trytoparseprimitivetypevalues":
5658
scope.TryToParsePrimitiveTypeValues = boolValue;
5759
break;
60+
case "ttpnt":
5861
case "trytoparsenumerictype":
5962
scope.TryToParseNumericType = boolValue;
6063
break;
64+
case "edv":
6165
case "excludedefaultvalues":
6266
scope.ExcludeDefaultValues = boolValue;
6367
break;
68+
case "inv":
6469
case "includenullvalues":
6570
scope.IncludeNullValues = boolValue;
6671
break;
72+
case "invid":
6773
case "includenullvaluesindictionaries":
6874
scope.IncludeNullValuesInDictionaries = boolValue;
6975
break;
76+
case "ide":
7077
case "includedefaultenums":
7178
scope.IncludeDefaultEnums = boolValue;
7279
break;
80+
case "eti":
7381
case "excludetypeinfo":
7482
scope.ExcludeTypeInfo = boolValue;
7583
break;
84+
case "iti":
7685
case "includetypeinfo":
7786
scope.IncludeTypeInfo = boolValue;
7887
break;
88+
case "eccn":
7989
case "emitcamelcasenames":
8090
scope.EmitCamelCaseNames = boolValue;
8191
break;
92+
case "elun":
8293
case "emitlowercaseunderscorenames":
8394
scope.EmitLowercaseUnderscoreNames = boolValue;
8495
break;
96+
case "pi":
8597
case "preferinterfaces":
8698
scope.PreferInterfaces = boolValue;
8799
break;
100+
case "tode":
88101
case "throwondeserializationerror":
89102
scope.ThrowOnDeserializationError = boolValue;
90103
break;
104+
case "teai":
91105
case "treatenumasinteger":
92106
scope.TreatEnumAsInteger = boolValue;
93107
break;
108+
case "sdtc":
94109
case "skipdatetimeconversion":
95110
scope.SkipDateTimeConversion = boolValue;
96111
break;
112+
case "auu":
97113
case "alwaysuseutc":
98114
scope.AlwaysUseUtc = boolValue;
99115
break;
116+
case "au":
100117
case "assumeutc":
101118
scope.AssumeUtc = boolValue;
102119
break;
120+
case "auo":
103121
case "appendutcoffset":
104122
scope.AppendUtcOffset = boolValue;
105123
break;
124+
case "eu":
106125
case "escapeunicode":
107126
scope.EscapeUnicode = boolValue;
108127
break;
128+
case "ipf":
109129
case "includepublicfields":
110130
scope.IncludePublicFields = boolValue;
111131
break;
132+
case "rsb":
112133
case "reuseStringBuffer":
113134
scope.ReuseStringBuffer = boolValue;
114135
break;
136+
case "dh":
115137
case "datehandler":
116138
switch (value)
117139
{
118140
case "timestampoffset":
141+
case "to":
119142
scope.DateHandler = DateHandler.TimestampOffset;
120143
break;
144+
case "dcjsc":
121145
case "dcjscompatible":
122146
scope.DateHandler = DateHandler.DCJSCompatible;
123147
break;
124148
case "iso8601":
125149
scope.DateHandler = DateHandler.ISO8601;
126150
break;
151+
case "iso8601do":
152+
case "iso8601dateonly":
153+
scope.DateHandler = DateHandler.ISO8601DateOnly;
154+
break;
155+
case "iso8601dt":
156+
case "iso8601datetime":
157+
scope.DateHandler = DateHandler.ISO8601DateTime;
158+
break;
127159
case "rfc1123":
128160
scope.DateHandler = DateHandler.RFC1123;
129161
break;
162+
case "ut":
130163
case "unixtime":
131164
scope.DateHandler = DateHandler.UnixTime;
132165
break;
166+
case "utm":
133167
case "unixtimems":
134168
scope.DateHandler = DateHandler.UnixTimeMs;
135169
break;
136170
}
137171
break;
172+
case "tsh":
138173
case "timespanhandler":
139174
switch (value)
140175
{
176+
case "df":
141177
case "durationformat":
142178
scope.TimeSpanHandler = TimeSpanHandler.DurationFormat;
143179
break;
180+
case "sf":
144181
case "standardformat":
145182
scope.TimeSpanHandler = TimeSpanHandler.StandardFormat;
146183
break;
147184
}
148185
break;
186+
case "pc":
149187
case "propertyconvention":
150188
switch (value)
151189
{
190+
case "l":
152191
case "lenient":
153192
scope.PropertyConvention = PropertyConvention.Lenient;
154193
break;
194+
case "s":
155195
case "strict":
156196
scope.PropertyConvention = PropertyConvention.Strict;
157197
break;
@@ -1255,6 +1295,8 @@ public enum DateHandler
12551295
TimestampOffset,
12561296
DCJSCompatible,
12571297
ISO8601,
1298+
ISO8601DateOnly,
1299+
ISO8601DateTime,
12581300
RFC1123,
12591301
UnixTime,
12601302
UnixTimeMs,

tests/ServiceStack.Text.Tests/JsConfigTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,5 +208,23 @@ public void Does_create_scope_from_string()
208208
Assert.That(scope.PropertyConvention, Is.EqualTo(PropertyConvention.Strict));
209209
scope.Dispose();
210210
}
211+
212+
[Test]
213+
public void Does_create_scope_from_string_using_CamelCaseHumps()
214+
{
215+
var scope = JsConfig.CreateScope("eccn,elun,inv:false,edv:0,ide:1");
216+
Assert.That(scope.EmitCamelCaseNames.Value);
217+
Assert.That(scope.EmitLowercaseUnderscoreNames.Value);
218+
Assert.That(!scope.IncludeNullValues.Value);
219+
Assert.That(!scope.ExcludeDefaultValues.Value);
220+
Assert.That(scope.IncludeDefaultEnums.Value);
221+
scope.Dispose();
222+
223+
scope = JsConfig.CreateScope("dh:ISO8601,tsh:df,pc:strict");
224+
Assert.That(scope.DateHandler, Is.EqualTo(DateHandler.ISO8601));
225+
Assert.That(scope.TimeSpanHandler, Is.EqualTo(TimeSpanHandler.DurationFormat));
226+
Assert.That(scope.PropertyConvention, Is.EqualTo(PropertyConvention.Strict));
227+
scope.Dispose();
228+
}
211229
}
212230
}

0 commit comments

Comments
 (0)