-Marked BSON classes as obsolete

This commit is contained in:
James Newton-King
2017-02-19 20:39:23 +13:00
parent 980cab1a22
commit 354249822a
20 changed files with 59 additions and 35 deletions
@@ -23,8 +23,8 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
#endregion #endregion
#pragma warning disable 618
#if !(NET20 || NET35 || NET40 || PORTABLE40) #if !(NET20 || NET35 || NET40 || PORTABLE40)
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
@@ -200,9 +200,7 @@ namespace Newtonsoft.Json.Tests.Bson
byte[] data = HexToBytes("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-02-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00"); byte[] data = HexToBytes("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-02-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00");
MemoryStream ms = new MemoryStream(data); MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms); BsonReader reader = new BsonReader(ms);
#pragma warning disable 612,618
reader.JsonNet35BinaryCompatibility = true; reader.JsonNet35BinaryCompatibility = true;
#pragma warning restore 612,618
reader.ReadRootValueAsArray = true; reader.ReadRootValueAsArray = true;
reader.DateTimeKindHandling = DateTimeKind.Utc; reader.DateTimeKindHandling = DateTimeKind.Utc;
@@ -409,9 +407,7 @@ namespace Newtonsoft.Json.Tests.Bson
MemoryStream ms = new MemoryStream(data); MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms, true, DateTimeKind.Utc); BsonReader reader = new BsonReader(ms, true, DateTimeKind.Utc);
#pragma warning disable 612,618
reader.JsonNet35BinaryCompatibility = true; reader.JsonNet35BinaryCompatibility = true;
#pragma warning restore 612,618
Assert.AreEqual(true, reader.ReadRootValueAsArray); Assert.AreEqual(true, reader.ReadRootValueAsArray);
Assert.AreEqual(DateTimeKind.Utc, reader.DateTimeKindHandling); Assert.AreEqual(DateTimeKind.Utc, reader.DateTimeKindHandling);
@@ -1344,3 +1340,4 @@ namespace Newtonsoft.Json.Tests.Bson
} }
#endif #endif
#pragma warning restore 618
@@ -23,6 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
#endregion #endregion
#pragma warning disable 618
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
@@ -284,9 +285,7 @@ namespace Newtonsoft.Json.Tests.Bson
byte[] data = HexToBytes("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-02-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00"); byte[] data = HexToBytes("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-02-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00");
MemoryStream ms = new MemoryStream(data); MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms); BsonReader reader = new BsonReader(ms);
#pragma warning disable 612,618
reader.JsonNet35BinaryCompatibility = true; reader.JsonNet35BinaryCompatibility = true;
#pragma warning restore 612,618
reader.ReadRootValueAsArray = true; reader.ReadRootValueAsArray = true;
reader.DateTimeKindHandling = DateTimeKind.Utc; reader.DateTimeKindHandling = DateTimeKind.Utc;
@@ -493,9 +492,7 @@ namespace Newtonsoft.Json.Tests.Bson
MemoryStream ms = new MemoryStream(data); MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms, true, DateTimeKind.Utc); BsonReader reader = new BsonReader(ms, true, DateTimeKind.Utc);
#pragma warning disable 612,618
reader.JsonNet35BinaryCompatibility = true; reader.JsonNet35BinaryCompatibility = true;
#pragma warning restore 612,618
Assert.AreEqual(true, reader.ReadRootValueAsArray); Assert.AreEqual(true, reader.ReadRootValueAsArray);
Assert.AreEqual(DateTimeKind.Utc, reader.DateTimeKindHandling); Assert.AreEqual(DateTimeKind.Utc, reader.DateTimeKindHandling);
@@ -632,9 +629,7 @@ namespace Newtonsoft.Json.Tests.Bson
byte[] data = HexToBytes(hexdoc); byte[] data = HexToBytes(hexdoc);
BsonReader reader = new BsonReader(new MemoryStream(data)); BsonReader reader = new BsonReader(new MemoryStream(data));
#pragma warning disable 612,618
reader.JsonNet35BinaryCompatibility = true; reader.JsonNet35BinaryCompatibility = true;
#pragma warning restore 612,618
JObject o = (JObject)JToken.ReadFrom(reader); JObject o = (JObject)JToken.ReadFrom(reader);
Assert.AreEqual(3, o.Count); Assert.AreEqual(3, o.Count);
@@ -655,9 +650,7 @@ namespace Newtonsoft.Json.Tests.Bson
"82-00-00-00-07-5F-69-64-00-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00"); "82-00-00-00-07-5F-69-64-00-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00");
BsonReader reader1 = new BsonReader(new MemoryStream(data1)); BsonReader reader1 = new BsonReader(new MemoryStream(data1));
#pragma warning disable 612,618
reader1.JsonNet35BinaryCompatibility = true; reader1.JsonNet35BinaryCompatibility = true;
#pragma warning restore 612,618
// oid // oid
JObject o1 = (JObject)JToken.ReadFrom(reader1); JObject o1 = (JObject)JToken.ReadFrom(reader1);
@@ -666,9 +659,7 @@ namespace Newtonsoft.Json.Tests.Bson
"87-00-00-00-05-5F-69-64-00-0C-00-00-00-02-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00"); "87-00-00-00-05-5F-69-64-00-0C-00-00-00-02-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00");
BsonReader reader2 = new BsonReader(new MemoryStream(data2)); BsonReader reader2 = new BsonReader(new MemoryStream(data2));
#pragma warning disable 612,618
reader2.JsonNet35BinaryCompatibility = true; reader2.JsonNet35BinaryCompatibility = true;
#pragma warning restore 612,618
// bytes // bytes
JObject o2 = (JObject)JToken.ReadFrom(reader2); JObject o2 = (JObject)JToken.ReadFrom(reader2);
@@ -1623,9 +1614,7 @@ namespace Newtonsoft.Json.Tests.Bson
var settings = new JsonSerializerSettings var settings = new JsonSerializerSettings
{ {
TypeNameHandling = TypeNameHandling.Auto, TypeNameHandling = TypeNameHandling.Auto,
#pragma warning disable CS0618 // Type or member is obsolete
Binder = binder Binder = binder
#pragma warning restore CS0618 // Type or member is obsolete
}; };
Zoo zoo = new Zoo Zoo zoo = new Zoo
@@ -1786,3 +1775,4 @@ namespace Newtonsoft.Json.Tests.Bson
} }
} }
} }
#pragma warning restore 618
@@ -23,8 +23,8 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
#endregion #endregion
#pragma warning disable 618
#if !(NET20 || NET35 || NET40 || PORTABLE40) #if !(NET20 || NET35 || NET40 || PORTABLE40)
using System; using System;
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1 #if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
using System.Numerics; using System.Numerics;
@@ -539,3 +539,4 @@ namespace Newtonsoft.Json.Tests.Bson
} }
#endif #endif
#pragma warning restore 618
@@ -23,6 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
#endregion #endregion
#pragma warning disable 618
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1 #if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
@@ -942,3 +943,4 @@ namespace Newtonsoft.Json.Tests.Bson
#endif #endif
} }
} }
#pragma warning restore 618
@@ -274,6 +274,7 @@ namespace Newtonsoft.Json.Tests.Converters
Assert.AreEqual(t1.TableName, t2.TableName); Assert.AreEqual(t1.TableName, t2.TableName);
} }
#pragma warning disable 618
[Test] [Test]
public void RoundtripBsonBytes() public void RoundtripBsonBytes()
{ {
@@ -314,6 +315,7 @@ namespace Newtonsoft.Json.Tests.Converters
CollectionAssert.AreEquivalent(Encoding.UTF8.GetBytes("Hello world!"), (byte[])dr1["data"]); CollectionAssert.AreEquivalent(Encoding.UTF8.GetBytes("Hello world!"), (byte[])dr1["data"]);
Assert.AreEqual(g, (Guid)dr1["id"]); Assert.AreEqual(g, (Guid)dr1["id"]);
} }
#pragma warning restore 618
[Test] [Test]
public void SerializeDataTableWithNull() public void SerializeDataTableWithNull()
@@ -23,6 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
#endregion #endregion
#pragma warning disable 618
using System.IO; using System.IO;
using Newtonsoft.Json.Bson; using Newtonsoft.Json.Bson;
using Newtonsoft.Json.Utilities; using Newtonsoft.Json.Utilities;
@@ -85,3 +86,4 @@ namespace Newtonsoft.Json.Tests.Converters
} }
} }
} }
#pragma warning restore 618
@@ -114,6 +114,7 @@ namespace Newtonsoft.Json.Tests.Converters
Assert.AreEqual(RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture, r.Regex.Options); Assert.AreEqual(RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture, r.Regex.Options);
} }
#pragma warning disable 618
[Test] [Test]
public void SerializeToBson() public void SerializeToBson()
{ {
@@ -132,19 +133,6 @@ namespace Newtonsoft.Json.Tests.Converters
Assert.AreEqual(expected, bson); Assert.AreEqual(expected, bson);
} }
[Test]
public void DeserializeFromText()
{
string json = @"{
""Pattern"": ""abc"",
""Options"": 513
}";
Regex newRegex = JsonConvert.DeserializeObject<Regex>(json, new RegexConverter());
Assert.AreEqual("abc", newRegex.ToString());
Assert.AreEqual(RegexOptions.IgnoreCase | RegexOptions.CultureInvariant, newRegex.Options);
}
[Test] [Test]
public void DeserializeFromBson() public void DeserializeFromBson()
{ {
@@ -209,6 +197,20 @@ namespace Newtonsoft.Json.Tests.Converters
Assert.AreEqual("/", c.Regex.ToString()); Assert.AreEqual("/", c.Regex.ToString());
Assert.AreEqual(RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.ExplicitCapture, c.Regex.Options); Assert.AreEqual(RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.ExplicitCapture, c.Regex.Options);
} }
#pragma warning restore 618
[Test]
public void DeserializeFromText()
{
string json = @"{
""Pattern"": ""abc"",
""Options"": 513
}";
Regex newRegex = JsonConvert.DeserializeObject<Regex>(json, new RegexConverter());
Assert.AreEqual("abc", newRegex.ToString());
Assert.AreEqual(RegexOptions.IgnoreCase | RegexOptions.CultureInvariant, newRegex.Options);
}
[Test] [Test]
public void ConvertEmptyRegexJson() public void ConvertEmptyRegexJson()
@@ -50,6 +50,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson
} }
#endregion #endregion
#pragma warning disable 618
[Test] [Test]
public void Example() public void Example()
{ {
@@ -67,6 +68,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson
// Movie Premiere // Movie Premiere
} }
#endregion #endregion
#pragma warning restore 618
} }
} }
} }
@@ -50,6 +50,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson
} }
#endregion #endregion
#pragma warning disable 618
[Test] [Test]
public void Example() public void Example()
{ {
@@ -73,6 +74,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson
// Easter // Easter
} }
#endregion #endregion
#pragma warning restore 618
} }
} }
} }
@@ -51,6 +51,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson
} }
#endregion #endregion
#pragma warning disable 618
[Test] [Test]
public void Example() public void Example()
{ {
@@ -76,5 +77,6 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson
Assert.AreEqual("MQAAAAJOYW1lAA8AAABNb3ZpZSBQcmVtaWVyZQAJU3RhcnREYXRlAED982M8AQAAAA==", data); Assert.AreEqual("MQAAAAJOYW1lAA8AAABNb3ZpZSBQcmVtaWVyZQAJU3RhcnREYXRlAED982M8AQAAAA==", data);
} }
#pragma warning restore 618
} }
} }
@@ -43,6 +43,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
[TestFixture] [TestFixture]
public class ReadJTokenFromBson : TestFixtureBase public class ReadJTokenFromBson : TestFixtureBase
{ {
#pragma warning disable 618
[Test] [Test]
public void Example() public void Example()
{ {
@@ -64,5 +65,6 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
Assert.AreEqual("value1", value); Assert.AreEqual("value1", value);
} }
#pragma warning restore 618
} }
} }
@@ -43,6 +43,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
[TestFixture] [TestFixture]
public class WriteJTokenToBson : TestFixtureBase public class WriteJTokenToBson : TestFixtureBase
{ {
#pragma warning disable 618
[Test] [Test]
public void Example() public void Example()
{ {
@@ -67,5 +68,6 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
Assert.AreEqual("KQAAAAJuYW1lMQAHAAAAdmFsdWUxAAJuYW1lMgAHAAAAdmFsdWUyAAA=", data); Assert.AreEqual("KQAAAAJuYW1lMQAHAAAAdmFsdWUxAAJuYW1lMgAHAAAAdmFsdWUyAAA=", data);
} }
#pragma warning restore 618
} }
} }
@@ -684,6 +684,7 @@ If attributes are not mentioned, default values are used in each case.
return Encoding.UTF8.GetBytes(json); return Encoding.UTF8.GetBytes(json);
}, "Json.NET"); }, "Json.NET");
#pragma warning disable 618
byte[] bsonBytes = TimeOperation(() => byte[] bsonBytes = TimeOperation(() =>
{ {
MemoryStream ms = null; MemoryStream ms = null;
@@ -699,6 +700,7 @@ If attributes are not mentioned, default values are used in each case.
return ms.ToArray(); return ms.ToArray();
}, "Json.NET BSON"); }, "Json.NET BSON");
#pragma warning restore 618
byte[] xmlBytes = TimeOperation(() => byte[] xmlBytes = TimeOperation(() =>
{ {
@@ -1051,6 +1053,7 @@ If attributes are not mentioned, default values are used in each case.
} }
break; break;
} }
#pragma warning disable 618
case SerializeMethod.JsonNetBinary: case SerializeMethod.JsonNetBinary:
{ {
MemoryStream ms = new MemoryStream(Buffer); MemoryStream ms = new MemoryStream(Buffer);
@@ -1062,6 +1065,7 @@ If attributes are not mentioned, default values are used in each case.
json = "Bytes = " + ms.Position; json = "Bytes = " + ms.Position;
break; break;
} }
#pragma warning restore 618
case SerializeMethod.JavaScriptSerializer: case SerializeMethod.JavaScriptSerializer:
json = SerializeWebExtensions(value); json = SerializeWebExtensions(value);
break; break;
@@ -1323,6 +1327,7 @@ If attributes are not mentioned, default values are used in each case.
return a; return a;
} }
#pragma warning disable 618
public T DeserializeJsonNetBinary<T>(byte[] bson) public T DeserializeJsonNetBinary<T>(byte[] bson)
{ {
Type type = typeof(T); Type type = typeof(T);
@@ -1334,6 +1339,7 @@ If attributes are not mentioned, default values are used in each case.
return (T)serializer.Deserialize(new BsonReader(new MemoryStream(bson)), type); return (T)serializer.Deserialize(new BsonReader(new MemoryStream(bson)), type);
} }
#pragma warning restore 618
public T DeserializeWebExtensions<T>(string json) public T DeserializeWebExtensions<T>(string json)
{ {
@@ -7771,6 +7771,7 @@ Path '', line 1, position 1.");
public DateTimeOffset Foo { get; set; } public DateTimeOffset Foo { get; set; }
} }
#pragma warning disable 618
[Test] [Test]
public void TokenFromBson() public void TokenFromBson()
{ {
@@ -7794,6 +7795,7 @@ Path '', line 1, position 1.");
""2000-01-02T03:04:05+06:00"" ""2000-01-02T03:04:05+06:00""
]", a.ToString()); ]", a.ToString());
} }
#pragma warning restore 618
[Test] [Test]
public void ObjectRequiredDeserializeMissing() public void ObjectRequiredDeserializeMissing()
+1
View File
@@ -31,6 +31,7 @@ namespace Newtonsoft.Json.Bson
/// <summary> /// <summary>
/// Represents a BSON Oid (object id). /// Represents a BSON Oid (object id).
/// </summary> /// </summary>
[Obsolete("BSON reading and writing has been moved to its own package. See https://www.nuget.org/packages/Newtonsoft.Json.Bson for more details.")]
public class BsonObjectId public class BsonObjectId
{ {
/// <summary> /// <summary>
+1
View File
@@ -37,6 +37,7 @@ namespace Newtonsoft.Json.Bson
/// <summary> /// <summary>
/// Represents a reader that provides fast, non-cached, forward-only access to serialized BSON data. /// Represents a reader that provides fast, non-cached, forward-only access to serialized BSON data.
/// </summary> /// </summary>
[Obsolete("BSON reading and writing has been moved to its own package. See https://www.nuget.org/packages/Newtonsoft.Json.Bson for more details.")]
public class BsonReader : JsonReader public class BsonReader : JsonReader
{ {
private const int MaxCharBytesSize = 128; private const int MaxCharBytesSize = 128;
+1
View File
@@ -40,6 +40,7 @@ namespace Newtonsoft.Json.Bson
/// <summary> /// <summary>
/// Represents a writer that provides a fast, non-cached, forward-only way of generating BSON data. /// Represents a writer that provides a fast, non-cached, forward-only way of generating BSON data.
/// </summary> /// </summary>
[Obsolete("BSON reading and writing has been moved to its own package. See https://www.nuget.org/packages/Newtonsoft.Json.Bson for more details.")]
public class BsonWriter : JsonWriter public class BsonWriter : JsonWriter
{ {
private readonly BsonBinaryWriter _writer; private readonly BsonBinaryWriter _writer;
@@ -33,6 +33,7 @@ namespace Newtonsoft.Json.Converters
/// <summary> /// <summary>
/// Converts a <see cref="BsonObjectId"/> to and from JSON and BSON. /// Converts a <see cref="BsonObjectId"/> to and from JSON and BSON.
/// </summary> /// </summary>
[Obsolete("BSON reading and writing has been moved to its own package. See https://www.nuget.org/packages/Newtonsoft.Json.Bson for more details.")]
public class BsonObjectIdConverter : JsonConverter public class BsonObjectIdConverter : JsonConverter
{ {
/// <summary> /// <summary>
@@ -49,11 +49,13 @@ namespace Newtonsoft.Json.Converters
{ {
Regex regex = (Regex)value; Regex regex = (Regex)value;
#pragma warning disable 618
BsonWriter bsonWriter = writer as BsonWriter; BsonWriter bsonWriter = writer as BsonWriter;
if (bsonWriter != null) if (bsonWriter != null)
{ {
WriteBson(bsonWriter, regex); WriteBson(bsonWriter, regex);
} }
#pragma warning restore 618
else else
{ {
WriteJson(writer, regex, serializer); WriteJson(writer, regex, serializer);
@@ -65,6 +67,7 @@ namespace Newtonsoft.Json.Converters
return ((options & flag) == flag); return ((options & flag) == flag);
} }
#pragma warning disable 618
private void WriteBson(BsonWriter writer, Regex regex) private void WriteBson(BsonWriter writer, Regex regex)
{ {
// Regular expression - The first cstring is the regex pattern, the second // Regular expression - The first cstring is the regex pattern, the second
@@ -100,6 +103,7 @@ namespace Newtonsoft.Json.Converters
writer.WriteRegex(regex.ToString(), options); writer.WriteRegex(regex.ToString(), options);
} }
#pragma warning restore 618
private void WriteJson(JsonWriter writer, Regex regex, JsonSerializer serializer) private void WriteJson(JsonWriter writer, Regex regex, JsonSerializer serializer)
{ {
@@ -80,7 +80,9 @@ namespace Newtonsoft.Json.Serialization
new DiscriminatedUnionConverter(), new DiscriminatedUnionConverter(),
#endif #endif
new KeyValuePairConverter(), new KeyValuePairConverter(),
#pragma warning disable 618
new BsonObjectIdConverter(), new BsonObjectIdConverter(),
#pragma warning restore 618
new RegexConverter() new RegexConverter()
}; };