-Added BigInteger support

This commit is contained in:
James Newton-King
2013-03-16 19:06:05 +13:00
parent b81dfd352a
commit 1356c31670
24 changed files with 957 additions and 50 deletions
+13 -4
View File
@@ -26,6 +26,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
using System.Numerics;
#endif
using System.Text;
using System.IO;
using System.Xml;
@@ -1245,13 +1248,19 @@ namespace Newtonsoft.Json
}
else
{
try
long value;
if (long.TryParse(number, out value))
{
numberValue = Convert.ToInt64(number, CultureInfo.InvariantCulture);
numberValue = value;
}
catch (OverflowException ex)
else
{
throw JsonReaderException.Create((JsonReader)this, "JSON integer {0} is too large or small for an Int64.".FormatWith(CultureInfo.InvariantCulture, number), ex);
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
numberValue = BigInteger.Parse(number, CultureInfo.InvariantCulture);
#else
// todo - validate number was a valid integer to make sure overflow was the reason for failure
throw JsonReaderException.Create((JsonReader)this, "JSON integer {0} is too large or small for an Int64.".FormatWith(CultureInfo.InvariantCulture, number));
#endif
}
numberType = JsonToken.Integer;