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

Commit 6309287

Browse files
committed
clean up
1 parent b5d9448 commit 6309287

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

src/ServiceStack.Text/Common/DeserializeType.cs

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,17 @@ public static object ParseAbstractType<T>(StringSegment value)
137137
public static object ParseQuotedPrimitive(string value)
138138
{
139139
var fn = JsConfig.ParsePrimitiveFn;
140-
if (fn != null)
141-
{
142-
var result = fn(value);
143-
if (result != null)
144-
return result;
145-
}
140+
var result = fn?.Invoke(value);
141+
if (result != null)
142+
return result;
146143

147144
if (string.IsNullOrEmpty(value))
148145
return null;
149146

150-
Guid guidValue;
151-
if (Guid.TryParse(value, out guidValue)) return guidValue;
147+
if (Guid.TryParse(value, out Guid guidValue)) return guidValue;
152148

153149
if (value.StartsWith(DateTimeSerializer.EscapedWcfJsonPrefix, StringComparison.Ordinal) || value.StartsWith(DateTimeSerializer.WcfJsonPrefix, StringComparison.Ordinal))
154-
{
155150
return DateTimeSerializer.ParseWcfJsonDate(value);
156-
}
157151

158152
if (JsConfig.DateHandler == DateHandler.ISO8601)
159153
{
@@ -188,24 +182,19 @@ public static object ParseQuotedPrimitive(string value)
188182
public static object ParsePrimitive(StringSegment value)
189183
{
190184
var fn = JsConfig.ParsePrimitiveFn;
191-
if (fn != null)
192-
{
193-
var result = fn(value.Value);
194-
if (result != null)
195-
return result;
196-
}
185+
var result = fn?.Invoke(value.Value);
186+
if (result != null)
187+
return result;
197188

198189
if (value.IsNullOrEmpty())
199190
return null;
200191

201-
bool boolValue;
202-
if (value.TryParseBoolean(out boolValue))
192+
if (value.TryParseBoolean(out bool boolValue))
203193
return boolValue;
204194

205195
// Parse as decimal
206-
decimal decimalValue;
207196
var acceptDecimal = JsConfig.ParsePrimitiveFloatingPointTypes.Has(ParseAsType.Decimal);
208-
var isDecimal = value.TryParseDecimal(out decimalValue);
197+
var isDecimal = value.TryParseDecimal(out decimal decimalValue);
209198

210199
// Check if the number is an Primitive Integer type given that we have a decimal
211200
if (isDecimal && decimalValue == decimal.Truncate(decimalValue))
@@ -229,15 +218,13 @@ public static object ParsePrimitive(StringSegment value)
229218
if (isDecimal && acceptDecimal)
230219
return decimalValue;
231220

232-
float floatValue;
233221
var acceptFloat = JsConfig.ParsePrimitiveFloatingPointTypes.HasFlag(ParseAsType.Single);
234-
var isFloat = value.TryParseFloat(out floatValue);
222+
var isFloat = value.TryParseFloat(out float floatValue);
235223
if (acceptFloat && isFloat)
236224
return floatValue;
237225

238-
double doubleValue;
239226
var acceptDouble = JsConfig.ParsePrimitiveFloatingPointTypes.HasFlag(ParseAsType.Double);
240-
var isDouble = value.TryParseDouble(out doubleValue);
227+
var isDouble = value.TryParseDouble(out double doubleValue);
241228
if (acceptDouble && isDouble)
242229
return doubleValue;
243230

@@ -347,14 +334,13 @@ private static SetMemberDelegate GetSetPropertyMethod(TypeConfig typeConfig, Pro
347334
FieldInfo fieldInfo = null;
348335
if (!propertyInfo.CanWrite)
349336
{
350-
//TODO: What string comparison is used in SST?
351-
string fieldNameFormat = Env.IsMono ? "<{0}>" : "<{0}>i__Field";
337+
var fieldNameFormat = Env.IsMono ? "<{0}>" : "<{0}>i__Field";
352338
var fieldName = string.Format(fieldNameFormat, propertyInfo.Name);
353339

354340
var fieldInfos = typeConfig.Type.GetWritableFields();
355341
foreach (var f in fieldInfos)
356342
{
357-
if (f.IsInitOnly && f.FieldType == propertyInfo.PropertyType && f.Name == fieldName)
343+
if (f.IsInitOnly && f.FieldType == propertyInfo.PropertyType && f.Name.EqualsIgnoreCase(fieldName))
358344
{
359345
fieldInfo = f;
360346
break;

0 commit comments

Comments
 (0)