-Added missing casts to JToken
-Upgraded to Immutable Collections RC -Tests
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user