@@ -188,22 +188,22 @@ public static object ParsePrimitive(string value)
188
188
189
189
// Parse as decimal
190
190
decimal decimalValue ;
191
- var acceptDecimal = JsConfig . ParsePrimitiveFloatingPointTypes . HasFlag ( ParseAsType . Decimal ) ;
191
+ var acceptDecimal = JsConfig . ParsePrimitiveFloatingPointTypes . Has ( ParseAsType . Decimal ) ;
192
192
var isDecimal = decimal . TryParse ( value , NumberStyles . Number , CultureInfo . InvariantCulture , out decimalValue ) ;
193
193
194
194
// Check if the number is an Primitive Integer type given that we have a decimal
195
195
if ( isDecimal && decimalValue == decimal . Truncate ( decimalValue ) )
196
196
{
197
197
// Value is a whole number
198
198
var parseAs = JsConfig . ParsePrimitiveIntegerTypes ;
199
- if ( parseAs . HasFlag ( ParseAsType . Byte ) && decimalValue <= byte . MaxValue && decimalValue >= byte . MinValue ) return ( byte ) decimalValue ;
200
- if ( parseAs . HasFlag ( ParseAsType . SByte ) && decimalValue <= sbyte . MaxValue && decimalValue >= sbyte . MinValue ) return ( sbyte ) decimalValue ;
201
- if ( parseAs . HasFlag ( ParseAsType . Int16 ) && decimalValue <= Int16 . MaxValue && decimalValue >= Int16 . MinValue ) return ( Int16 ) decimalValue ;
202
- if ( parseAs . HasFlag ( ParseAsType . UInt16 ) && decimalValue <= UInt16 . MaxValue && decimalValue >= UInt16 . MinValue ) return ( UInt16 ) decimalValue ;
203
- if ( parseAs . HasFlag ( ParseAsType . Int32 ) && decimalValue <= Int32 . MaxValue && decimalValue >= Int32 . MinValue ) return ( Int32 ) decimalValue ;
204
- if ( parseAs . HasFlag ( ParseAsType . UInt32 ) && decimalValue <= UInt32 . MaxValue && decimalValue >= UInt32 . MinValue ) return ( UInt32 ) decimalValue ;
205
- if ( parseAs . HasFlag ( ParseAsType . Int64 ) && decimalValue <= Int64 . MaxValue && decimalValue >= Int64 . MinValue ) return ( Int64 ) decimalValue ;
206
- if ( parseAs . HasFlag ( ParseAsType . UInt64 ) && decimalValue <= UInt64 . MaxValue && decimalValue >= UInt64 . MinValue ) return ( UInt64 ) decimalValue ;
199
+ if ( parseAs . Has ( ParseAsType . Byte ) && decimalValue <= byte . MaxValue && decimalValue >= byte . MinValue ) return ( byte ) decimalValue ;
200
+ if ( parseAs . Has ( ParseAsType . SByte ) && decimalValue <= sbyte . MaxValue && decimalValue >= sbyte . MinValue ) return ( sbyte ) decimalValue ;
201
+ if ( parseAs . Has ( ParseAsType . Int16 ) && decimalValue <= Int16 . MaxValue && decimalValue >= Int16 . MinValue ) return ( Int16 ) decimalValue ;
202
+ if ( parseAs . Has ( ParseAsType . UInt16 ) && decimalValue <= UInt16 . MaxValue && decimalValue >= UInt16 . MinValue ) return ( UInt16 ) decimalValue ;
203
+ if ( parseAs . Has ( ParseAsType . Int32 ) && decimalValue <= Int32 . MaxValue && decimalValue >= Int32 . MinValue ) return ( Int32 ) decimalValue ;
204
+ if ( parseAs . Has ( ParseAsType . UInt32 ) && decimalValue <= UInt32 . MaxValue && decimalValue >= UInt32 . MinValue ) return ( UInt32 ) decimalValue ;
205
+ if ( parseAs . Has ( ParseAsType . Int64 ) && decimalValue <= Int64 . MaxValue && decimalValue >= Int64 . MinValue ) return ( Int64 ) decimalValue ;
206
+ if ( parseAs . Has ( ParseAsType . UInt64 ) && decimalValue <= UInt64 . MaxValue && decimalValue >= UInt64 . MinValue ) return ( UInt64 ) decimalValue ;
207
207
return decimalValue ;
208
208
}
209
209
@@ -351,4 +351,12 @@ private static SetPropertyDelegate GetSetFieldMethod(TypeConfig typeConfig, Fiel
351
351
return PclExport . Instance . GetSetFieldMethod ( fieldInfo ) ;
352
352
}
353
353
}
354
+
355
+ internal static class DeserializeTypeExensions
356
+ {
357
+ public static bool Has ( this ParseAsType flags , ParseAsType flag )
358
+ {
359
+ return ( flag & flags ) != 0 ;
360
+ }
361
+ }
354
362
}
0 commit comments