-Fixed converting BigInteger to IConvertable type when deserializing

-Updated build and NuGet files for upgraded builds
This commit is contained in:
James Newton-King
2013-03-24 21:37:29 +13:00
parent d9d96b3e5c
commit e5ee60497e
6 changed files with 72 additions and 47 deletions
+18 -15
View File
@@ -317,6 +317,22 @@ namespace Newtonsoft.Json.Utilities
throw new InvalidCastException("Cannot convert {0} to BigInteger.".FormatWith(CultureInfo.InvariantCulture, value.GetType()));
}
public static object FromBigInteger(BigInteger i, Type targetType)
{
if (targetType == typeof (decimal))
return (decimal) i;
if (targetType == typeof (double))
return (double) i;
if (targetType == typeof (float))
return (float) i;
if (targetType == typeof (ulong))
return (ulong) i;
if (IsConvertible(targetType))
return System.Convert.ChangeType((long) i, targetType, CultureInfo.InvariantCulture);
throw new InvalidOperationException("Can not convert from BigInteger to {0}.".FormatWith(CultureInfo.InvariantCulture, targetType));
}
#endif
#region Convert
@@ -377,23 +393,9 @@ namespace Newtonsoft.Json.Utilities
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
if (targetType == typeof(BigInteger))
{
return ToBigInteger(initialValue);
}
if (initialValue is BigInteger)
{
BigInteger i = (BigInteger) initialValue;
if (targetType == typeof(decimal))
return (decimal) i;
if (targetType == typeof(double))
return (double) i;
if (targetType == typeof(float))
return (float) i;
if (targetType == typeof(ulong))
return (ulong) i;
if (IsConvertible(targetType))
return System.Convert.ChangeType((long) i, targetType, CultureInfo.InvariantCulture);
}
return FromBigInteger((BigInteger)initialValue, targetType);
#endif
#if !(NETFX_CORE || PORTABLE)
@@ -437,6 +439,7 @@ namespace Newtonsoft.Json.Utilities
throw new InvalidOperationException("Can not convert from {0} to {1}.".FormatWith(CultureInfo.InvariantCulture, initialType, targetType));
}
#endregion
#region TryConvert