-Added support for converting byte array JValues to Guid

-Added support for deserializing byte arrays to Guid
-Changed Guids to be serialized as binary UUID in BSON
-Changed JsonNet35BinaryCompatibility on BsonReader to be obsolete
This commit is contained in:
James Newton-King
2013-04-07 15:07:35 +12:00
parent 1abcfb1ace
commit 341656e7eb
11 changed files with 130 additions and 18 deletions
@@ -371,17 +371,14 @@ namespace Newtonsoft.Json.Utilities
return System.Convert.ChangeType(initialValue, targetType, culture);
}
if (initialValue is string && typeof(Type).IsAssignableFrom(targetType))
return Type.GetType((string) initialValue, true);
if (targetType.IsInterface() || targetType.IsGenericTypeDefinition() || targetType.IsAbstract())
throw new ArgumentException("Target type {0} is not a value type or a non-abstract class.".FormatWith(CultureInfo.InvariantCulture, targetType), "targetType");
#if !NET20
if (initialValue is DateTime && targetType == typeof(DateTimeOffset))
return new DateTimeOffset((DateTime)initialValue);
#endif
if (initialValue is byte[] && targetType == typeof(Guid))
return new Guid((byte[]) initialValue);
if (initialValue is string)
{
if (targetType == typeof (Guid))
@@ -390,6 +387,8 @@ namespace Newtonsoft.Json.Utilities
return new Uri((string) initialValue, UriKind.RelativeOrAbsolute);
if (targetType == typeof(TimeSpan))
return ParseTimeSpan((string) initialValue);
if (typeof(Type).IsAssignableFrom(targetType))
return Type.GetType((string) initialValue, true);
}
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE40 || PORTABLE)
@@ -399,6 +398,9 @@ namespace Newtonsoft.Json.Utilities
return FromBigInteger((BigInteger)initialValue, targetType);
#endif
if (targetType.IsInterface() || targetType.IsGenericTypeDefinition() || targetType.IsAbstract())
throw new ArgumentException("Target type {0} is not a value type or a non-abstract class.".FormatWith(CultureInfo.InvariantCulture, targetType), "targetType");
#if !(NETFX_CORE || PORTABLE40 || PORTABLE)
// see if source or target types have a TypeConverter that converts between the two
TypeConverter toConverter = GetConverter(initialType);