-Added reading and writing binary JSON (BSON) support - work in progress

-Added BsonReader, BsonWriter
-Added support for reading and writing byte arrays to JsonReader, JsonWriter and LINQ to JSON classes
-Added ReadAsBytes to JsonReader
-Changed Silverlight build serializer to look for a TypeConverter
-Changed .NET build to not rely on System.ComponentModel.DataAnnotations assembly to support .NET 4.0 client profile
-Remove DateTimeOffset stand-in from Compact Framework build
-Fixed .NET 2.0 build to run on environments without .NET 2.0 SP1
-Fixed deserialization to always use a new value created from a JsonConverter
-Fixed XmlNodeConverter to support converting comments in JSON
This commit is contained in:
JamesNK
2009-12-06 23:10:14 +00:00
parent 7d845d1f13
commit f1a9993723
59 changed files with 1952 additions and 697 deletions
+27
View File
@@ -400,6 +400,11 @@ namespace Newtonsoft.Json.Linq
return (o.Type == JTokenType.String || o.Type == JTokenType.Comment || o.Type == JTokenType.Raw || IsNullable(o));
}
private static bool ValidateBytes(JToken o)
{
return (o.Type == JTokenType.Bytes || IsNullable(o));
}
private static string GetType(JToken t)
{
return (t != null) ? t.Type.ToString() : "{null}";
@@ -420,6 +425,7 @@ namespace Newtonsoft.Json.Linq
return (bool)v.Value;
}
#if !PocketPC && !NET20
/// <summary>
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="System.DateTimeOffset"/>.
/// </summary>
@@ -433,6 +439,7 @@ namespace Newtonsoft.Json.Linq
return (DateTimeOffset)v.Value;
}
#endif
/// <summary>
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="Nullable{Boolean}"/>.
@@ -482,6 +489,7 @@ namespace Newtonsoft.Json.Linq
return (DateTime?)v.Value;
}
#if !PocketPC && !NET20
/// <summary>
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="Nullable{DateTimeOffset}"/>.
/// </summary>
@@ -498,6 +506,7 @@ namespace Newtonsoft.Json.Linq
return (DateTimeOffset?)v.Value;
}
#endif
/// <summary>
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="Nullable{Decimal}"/>.
@@ -732,6 +741,15 @@ namespace Newtonsoft.Json.Linq
return Convert.ToUInt64(v.Value, CultureInfo.InvariantCulture);
}
public static explicit operator byte[](JToken value)
{
JValue v = EnsureValue(value);
if (v == null || !ValidateBytes(v))
throw new ArgumentException("Can not convert {0} to byte array.".FormatWith(CultureInfo.InvariantCulture, GetType(v)));
return (byte[])v.Value;
}
#endregion
#region Cast to operators
@@ -745,6 +763,7 @@ namespace Newtonsoft.Json.Linq
return new JValue(value);
}
#if !PocketPC && !NET20
/// <summary>
/// Performs an implicit conversion from <see cref="DateTimeOffset"/> to <see cref="JToken"/>.
/// </summary>
@@ -754,6 +773,7 @@ namespace Newtonsoft.Json.Linq
{
return new JValue(value);
}
#endif
/// <summary>
/// Performs an implicit conversion from <see cref="Nullable{Boolean}"/> to <see cref="JToken"/>.
@@ -785,6 +805,7 @@ namespace Newtonsoft.Json.Linq
return new JValue(value);
}
#if !PocketPC && !NET20
/// <summary>
/// Performs an implicit conversion from <see cref="Nullable{DateTimeOffset}"/> to <see cref="JToken"/>.
/// </summary>
@@ -794,6 +815,7 @@ namespace Newtonsoft.Json.Linq
{
return new JValue(value);
}
#endif
/// <summary>
/// Performs an implicit conversion from <see cref="Nullable{Decimal}"/> to <see cref="JToken"/>.
@@ -964,6 +986,11 @@ namespace Newtonsoft.Json.Linq
{
return new JValue(value);
}
public static implicit operator JToken(byte[] value)
{
return new JValue(value);
}
#endregion
IEnumerator IEnumerable.GetEnumerator()