@@ -188,22 +188,22 @@ public static object ParsePrimitive(string value)
188188
189189 // Parse as decimal
190190 decimal decimalValue ;
191- var acceptDecimal = JsConfig . ParsePrimitiveFloatingPointTypes . HasFlag ( ParseAsType . Decimal ) ;
191+ var acceptDecimal = JsConfig . ParsePrimitiveFloatingPointTypes . Has ( ParseAsType . Decimal ) ;
192192 var isDecimal = decimal . TryParse ( value , NumberStyles . Number , CultureInfo . InvariantCulture , out decimalValue ) ;
193193
194194 // Check if the number is an Primitive Integer type given that we have a decimal
195195 if ( isDecimal && decimalValue == decimal . Truncate ( decimalValue ) )
196196 {
197197 // Value is a whole number
198198 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 ;
207207 return decimalValue ;
208208 }
209209
@@ -351,4 +351,12 @@ private static SetPropertyDelegate GetSetFieldMethod(TypeConfig typeConfig, Fiel
351351 return PclExport . Instance . GetSetFieldMethod ( fieldInfo ) ;
352352 }
353353 }
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+ }
354362}
0 commit comments