* JsonReader.cs : It seems it can either return int, long or decimal
depending on the value. Users cannot really predict what type of
the primitive value can be returned and casts to specific types
very likely fail. doh.
svn path=/trunk/mcs/; revision=150285
+2010-01-27 Atsushi Enomoto <atsushi@ximian.com>
+
+ * JsonReader.cs : It seems it can either return int, long or decimal
+ depending on the value. Users cannot really predict what type of
+ the primitive value can be returned and casts to specific types
+ very likely fail. doh.
+
2010-01-27 Atsushi Enomoto <atsushi@ximian.com>
* JsonReader.cs : use decimal instead of int to parse decimal part
}
}
+ // It could return either int, long or decimal, depending on the parsed value.
JsonPrimitive ReadNumericLiteral ()
{
bool negative = false;
if (!hasFrac)
return new JsonPrimitive (negative ? -val : val);
var v = val + frac;
+ if (frac == 0) {
+ if (negative && int.MinValue <= -v ||
+ !negative && v <= int.MaxValue)
+ return new JsonPrimitive ((int) (negative ? -v : v));
+ if (negative && long.MinValue <= -v ||
+ !negative && v <= long.MaxValue)
+ return new JsonPrimitive ((long) (negative ? -v : v));
+ }
return new JsonPrimitive (negative ? -v : v);
}