-Added missing casts to JToken

-Upgraded to Immutable Collections RC
-Tests
This commit is contained in:
James Newton-King
2013-09-13 20:15:30 +12:00
parent 4922c4eedc
commit 5512e2623c
27 changed files with 4688 additions and 12022 deletions
+81
View File
@@ -734,6 +734,25 @@ namespace Newtonsoft.Json.Linq
return Convert.ToByte(v.Value, CultureInfo.InvariantCulture);
}
/// <summary>
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="System.SByte"/>.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The result of the conversion.</returns>
public static explicit operator sbyte(JToken value)
{
JValue v = EnsureValue(value);
if (v == null || !ValidateToken(v, NumberTypes, false))
throw new ArgumentException("Can not convert {0} to SByte.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE40 || PORTABLE)
if (v.Value is BigInteger)
return (sbyte)(BigInteger)v.Value;
#endif
return Convert.ToSByte(v.Value, CultureInfo.InvariantCulture);
}
/// <summary>
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="Nullable{Int32}"/>.
/// </summary>
@@ -823,6 +842,28 @@ namespace Newtonsoft.Json.Linq
return (v.Value != null) ? (byte?)Convert.ToByte(v.Value, CultureInfo.InvariantCulture) : null;
}
/// <summary>
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="Nullable{SByte}"/>.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The result of the conversion.</returns>
public static explicit operator sbyte?(JToken value)
{
if (value == null)
return null;
JValue v = EnsureValue(value);
if (v == null || !ValidateToken(v, NumberTypes, true))
throw new ArgumentException("Can not convert {0} to SByte.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE40 || PORTABLE)
if (v.Value is BigInteger)
return (sbyte?)(BigInteger)v.Value;
#endif
return (v.Value != null) ? (sbyte?)Convert.ToByte(v.Value, CultureInfo.InvariantCulture) : null;
}
/// <summary>
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="System.DateTime"/>.
/// </summary>
@@ -1223,6 +1264,46 @@ namespace Newtonsoft.Json.Linq
}
#endif
/// <summary>
/// Performs an implicit conversion from <see cref="Byte"/> to <see cref="JToken"/>.
/// </summary>
/// <param name="value">The value to create a <see cref="JValue"/> from.</param>
/// <returns>The <see cref="JValue"/> initialized with the specified value.</returns>
public static implicit operator JToken(byte value)
{
return new JValue(value);
}
/// <summary>
/// Performs an implicit conversion from <see cref="Nullable{Byte}"/> to <see cref="JToken"/>.
/// </summary>
/// <param name="value">The value to create a <see cref="JValue"/> from.</param>
/// <returns>The <see cref="JValue"/> initialized with the specified value.</returns>
public static implicit operator JToken(byte? value)
{
return new JValue(value);
}
/// <summary>
/// Performs an implicit conversion from <see cref="SByte"/> to <see cref="JToken"/>.
/// </summary>
/// <param name="value">The value to create a <see cref="JValue"/> from.</param>
/// <returns>The <see cref="JValue"/> initialized with the specified value.</returns>
public static implicit operator JToken(sbyte value)
{
return new JValue(value);
}
/// <summary>
/// Performs an implicit conversion from <see cref="Nullable{SByte}"/> to <see cref="JToken"/>.
/// </summary>
/// <param name="value">The value to create a <see cref="JValue"/> from.</param>
/// <returns>The <see cref="JValue"/> initialized with the specified value.</returns>
public static implicit operator JToken(sbyte? value)
{
return new JValue(value);
}
/// <summary>
/// Performs an implicit conversion from <see cref="Nullable{Boolean}"/> to <see cref="JToken"/>.
/// </summary>