Permalink
Browse files

Merge branch 'csharp562v18'

  • Loading branch information...
2 parents e13c7ba + cf64c55 commit 5825955911d86b2adfd27a60099a7a6915395b60 rstam committed Dec 12, 2012
Showing with 703 additions and 978 deletions.
  1. +5 −15 MongoDB.Bson/ObjectModel/BsonArray.cs
  2. +30 −144 MongoDB.Bson/ObjectModel/BsonDocument.cs
  3. +27 −20 MongoDB.Bson/ObjectModel/BsonDocumentWrapper.cs
  4. +0 −44 MongoDB.Bson/ObjectModel/BsonElement.cs
  5. +4 −153 MongoDB.Bson/ObjectModel/BsonValue.cs
  6. +5 −0 MongoDB.Bson/Serialization/BsonDefaultSerializationProvider.cs
  7. +10 −0 MongoDB.Bson/Serialization/BsonMemberMap.cs
  8. +22 −2 MongoDB.Bson/Serialization/BsonSerializer.cs
  9. +2 −1 MongoDB.Bson/Serialization/Conventions/DiscriminatorConventions.cs
  10. +22 −13 MongoDB.Bson/Serialization/Serializers/BsonArraySerializer.cs
  11. +26 −32 MongoDB.Bson/Serialization/Serializers/BsonBinaryDataSerializer.cs
  12. +10 −15 MongoDB.Bson/Serialization/Serializers/BsonBooleanSerializer.cs
  13. +67 −18 MongoDB.Bson/Serialization/Serializers/BsonClassMapSerializer.cs
  14. +10 −175 MongoDB.Bson/Serialization/Serializers/BsonDateTimeSerializer.cs
  15. +118 −7 MongoDB.Bson/Serialization/Serializers/BsonDocumentSerializer.cs
  16. +20 −3 MongoDB.Bson/Serialization/Serializers/BsonDocumentWrapperSerializer.cs
  17. +11 −15 MongoDB.Bson/Serialization/Serializers/BsonDoubleSerializer.cs
  18. +11 −15 MongoDB.Bson/Serialization/Serializers/BsonInt32Serializer.cs
  19. +11 −15 MongoDB.Bson/Serialization/Serializers/BsonInt64Serializer.cs
  20. +12 −14 MongoDB.Bson/Serialization/Serializers/BsonJavaScriptSerializer.cs
  21. +14 −16 MongoDB.Bson/Serialization/Serializers/BsonJavaScriptWithScopeSerializer.cs
  22. +12 −13 MongoDB.Bson/Serialization/Serializers/BsonMaxKeySerializer.cs
  23. +12 −13 MongoDB.Bson/Serialization/Serializers/BsonMinKeySerializer.cs
  24. +5 −23 MongoDB.Bson/Serialization/Serializers/BsonNullSerializer.cs
  25. +11 −15 MongoDB.Bson/Serialization/Serializers/BsonObjectIdSerializer.cs
  26. +11 −15 MongoDB.Bson/Serialization/Serializers/BsonRegularExpressionSerializer.cs
  27. +11 −15 MongoDB.Bson/Serialization/Serializers/BsonStringSerializer.cs
  28. +3 −25 MongoDB.Bson/Serialization/Serializers/BsonSymbolSerializer.cs
  29. +11 −15 MongoDB.Bson/Serialization/Serializers/BsonTimestampSerializer.cs
  30. +11 −13 MongoDB.Bson/Serialization/Serializers/BsonUndefinedSerializer.cs
  31. +47 −11 MongoDB.Bson/Serialization/Serializers/BsonValueSerializer.cs
  32. +1 −1 MongoDB.Bson/Serialization/Serializers/DecimalSerializer.cs
  33. +15 −14 MongoDB.BsonUnitTests/IO/BsonDocumentReaderTests.cs
  34. +4 −3 MongoDB.BsonUnitTests/IO/BsonRoundTripTests.cs
  35. +0 −4 MongoDB.BsonUnitTests/IO/JsonWriterTests.cs
  36. +6 −11 MongoDB.BsonUnitTests/Jira/CSharp446Tests.cs
  37. +12 −11 MongoDB.BsonUnitTests/ObjectModel/BsonDocumentTests.cs
  38. +62 −39 MongoDB.BsonUnitTests/Serialization/Serializers/BsonValueSerializerTests.cs
  39. +1 −1 MongoDB.BsonUnitTests/Serialization/Serializers/CircularReferencesTests.cs
  40. +2 −1 MongoDB.Driver/Builders/CollectionOptionsBuilder.cs
  41. +2 −1 MongoDB.Driver/Builders/FieldsBuilder.cs
  42. +2 −1 MongoDB.Driver/Builders/GeoHaystackSearchOptionsBuilder.cs
  43. +2 −1 MongoDB.Driver/Builders/GeoNearOptionsBuilder.cs
  44. +2 −1 MongoDB.Driver/Builders/GroupByBuilder.cs
  45. +2 −1 MongoDB.Driver/Builders/IndexKeysBuilder.cs
  46. +2 −1 MongoDB.Driver/Builders/IndexOptionsBuilder.cs
  47. +3 −2 MongoDB.Driver/Builders/MapReduceOptionsBuilder.cs
  48. +2 −1 MongoDB.Driver/Builders/SortByBuilder.cs
  49. +2 −2 MongoDB.Driver/Builders/UpdateBuilder.cs
  50. +3 −2 MongoDB.Driver/Communication/Messages/MongoReplyMessage.cs
  51. +2 −1 MongoDB.Driver/GridFS/MongoGridFSFileInfo.cs
  52. +2 −2 MongoDB.Driver/MongoDBRef.cs
  53. +2 −1 MongoDB.DriverUnitTests/Jira/CSharp231Tests.cs
  54. +1 −1 MongoDB.DriverUnitTests/Jira/CSharp365Tests.cs
@@ -21,6 +21,7 @@
using System.Text.RegularExpressions;
using MongoDB.Bson.IO;
+using MongoDB.Bson.Serialization;
namespace MongoDB.Bson
{
@@ -412,17 +413,10 @@ public new static BsonArray Create(object value)
/// </summary>
/// <param name="bsonReader">The reader.</param>
/// <returns>A BsonArray.</returns>
+ [Obsolete("Use BsonSerializer.Deserialize<BsonArray> instead.")]
public static new BsonArray ReadFrom(BsonReader bsonReader)
{
- var array = new BsonArray();
- bsonReader.ReadStartArray();
- while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
- {
- var value = BsonValue.ReadFrom(bsonReader);
- array.Add(value);
- }
- bsonReader.ReadEndArray();
- return array;
+ return BsonSerializer.Deserialize<BsonArray>(bsonReader);
}
// public methods
@@ -870,14 +864,10 @@ public override string ToString()
/// Writes the array to a BsonWriter.
/// </summary>
/// <param name="bsonWriter">The writer.</param>
+ [Obsolete("Use BsonSerializer.Serialize<BsonArray> instead.")]
public new void WriteTo(BsonWriter bsonWriter)
{
- bsonWriter.WriteStartArray();
- for (int i = 0; i < _values.Count; i++)
- {
- _values[i].WriteTo(bsonWriter);
- }
- bsonWriter.WriteEndArray();
+ BsonSerializer.Serialize(bsonWriter, this);
}
// explicit interface implementations
@@ -26,6 +26,7 @@
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.IdGenerators;
using MongoDB.Bson.Serialization.Options;
+using MongoDB.Bson.Serialization.Serializers;
namespace MongoDB.Bson
{
@@ -371,8 +372,7 @@ public static BsonDocument Parse(string json)
{
using (var bsonReader = BsonReader.Create(json))
{
- var document = new BsonDocument();
- return (BsonDocument)((IBsonSerializable)document).Deserialize(bsonReader, typeof(BsonDocument), null);
+ return (BsonDocument)BsonDocumentSerializer.Instance.Deserialize(bsonReader, typeof(BsonDocument), null);
}
}
@@ -381,11 +381,12 @@ public static BsonDocument Parse(string json)
/// </summary>
/// <param name="buffer">The BsonBuffer.</param>
/// <returns>A BsonDocument.</returns>
+ [Obsolete("Use BsonSerializer.Deserialize<BsonDocument> instead.")]
public static BsonDocument ReadFrom(BsonBuffer buffer)
{
using (BsonReader bsonReader = BsonReader.Create(buffer))
{
- return ReadFrom(bsonReader);
+ return BsonSerializer.Deserialize<BsonDocument>(bsonReader);
}
}
@@ -394,50 +395,45 @@ public static BsonDocument ReadFrom(BsonBuffer buffer)
/// </summary>
/// <param name="bsonReader">The BsonReader.</param>
/// <returns>A BsonDocument.</returns>
+ [Obsolete("Use BsonSerializer.Deserialize<BsonDocument> instead.")]
public static new BsonDocument ReadFrom(BsonReader bsonReader)
{
- BsonDocument document = new BsonDocument();
- return (BsonDocument)((IBsonSerializable)document).Deserialize(bsonReader, typeof(BsonDocument), null);
+ return BsonSerializer.Deserialize<BsonDocument>(bsonReader);
}
/// <summary>
/// Reads a BsonDocument from a byte array.
/// </summary>
/// <param name="bytes">The byte array.</param>
/// <returns>A BsonDocument.</returns>
+ [Obsolete("Use BsonSerializer.Deserialize<BsonDocument> instead.")]
public static BsonDocument ReadFrom(byte[] bytes)
{
- MemoryStream stream = new MemoryStream(bytes);
- using (BsonReader bsonReader = BsonReader.Create(stream))
- {
- return ReadFrom(bsonReader);
- }
+ return BsonSerializer.Deserialize<BsonDocument>(bytes);
}
/// <summary>
/// Reads a BsonDocument from a stream.
/// </summary>
/// <param name="stream">The stream.</param>
/// <returns>A BsonDocument.</returns>
+ [Obsolete("Use BsonSerializer.Deserialize<BsonDocument> instead.")]
public static BsonDocument ReadFrom(Stream stream)
{
- using (BsonReader bsonReader = BsonReader.Create(stream))
- {
- return ReadFrom(bsonReader);
- }
+ return BsonSerializer.Deserialize<BsonDocument>(stream);
}
/// <summary>
/// Reads a BsonDocument from a file.
/// </summary>
/// <param name="filename">The name of the file.</param>
/// <returns>A BsonDocument.</returns>
+ [Obsolete("Use BsonSerializer.Deserialize<BsonDocument> instead.")]
public static BsonDocument ReadFrom(string filename)
{
- FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None);
- using (BsonReader bsonReader = BsonReader.Create(stream))
+ using (var stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None))
{
- return ReadFrom(bsonReader);
+ return BsonSerializer.Deserialize<BsonDocument>(stream);
}
}
@@ -796,34 +792,7 @@ public override BsonValue DeepClone()
[Obsolete("Deserialize was intended to be private and will become private in a future release.")]
public object Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options)
{
- if (bsonReader.GetCurrentBsonType() == Bson.BsonType.Null)
- {
- bsonReader.ReadNull();
- return null;
- }
- else
- {
- var documentSerializationOptions = (options ?? DocumentSerializationOptions.Defaults) as DocumentSerializationOptions;
- if (documentSerializationOptions == null)
- {
- var message = string.Format(
- "Serialize method of BsonDocument expected serialization options of type {0}, not {1}.",
- BsonUtils.GetFriendlyTypeName(typeof(DocumentSerializationOptions)),
- BsonUtils.GetFriendlyTypeName(options.GetType()));
- throw new BsonSerializationException(message);
- }
- _allowDuplicateNames = documentSerializationOptions.AllowDuplicateNames;
-
- bsonReader.ReadStartDocument();
- Clear();
- BsonElement element;
- while (BsonElement.ReadFrom(bsonReader, out element))
- {
- Add(element);
- }
- bsonReader.ReadEndDocument();
- return this;
- }
+ return BsonDocumentSerializer.Instance.Deserialize(bsonReader, nominalType, options);
}
/// <summary>
@@ -836,37 +805,8 @@ public object Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializ
[Obsolete("GetDocumentId was intended to be private and will become private in a future release. Use document[\"_id\"] or document.GetValue(\"_id\") instead.")]
public bool GetDocumentId(out object id, out Type idNominalType, out IIdGenerator idGenerator)
{
- BsonElement idElement;
- if (TryGetElement("_id", out idElement))
- {
- // TODO: in a future release we will always return a BsonValue (GetDocumentId is not supposed to transform Id values in any way)
- // we're returning the raw value in 1.4.2 to remain temporarily backward compatible with 1.4.0 and earlier
- id = idElement.Value.RawValue;
- if (id == null)
- {
- id = idElement.Value;
- }
- idGenerator = BsonSerializer.LookupIdGenerator(id.GetType());
-
- if (idGenerator == null)
- {
- // note: in 1.4.2 this code isn't yet used because if the RawValue was a Guid then the GuidIdGenerator was found
- // but once we start returning BsonValue like we should this code will start being used
- var idBinaryData = id as BsonBinaryData;
- if (idBinaryData != null && (idBinaryData.SubType == BsonBinarySubType.UuidLegacy || idBinaryData.SubType == BsonBinarySubType.UuidStandard))
- {
- idGenerator = BsonBinaryDataGuidGenerator.GetInstance(idBinaryData.GuidRepresentation);
- }
- }
- }
- else
- {
- id = null;
- idGenerator = ObjectIdGenerator.Instance; // TODO: in a future release we will return an instance of BsonObjectIdGenerator
- }
-
- idNominalType = typeof(BsonValue);
- return true;
+ var idProvider = (IBsonIdProvider)BsonDocumentSerializer.Instance;
+ return idProvider.GetDocumentId(this, out id, out idNominalType, out idGenerator);
}
/// <summary>
@@ -1102,45 +1042,7 @@ public void RemoveElement(BsonElement element)
[Obsolete("Serialize was intended to be private and will become private in a future release.")]
public void Serialize(BsonWriter bsonWriter, Type nominalType, IBsonSerializationOptions options)
{
- if (bsonWriter == null)
- {
- throw new ArgumentNullException("bsonWriter");
- }
- if (nominalType == null)
- {
- throw new ArgumentNullException("nominalType");
- }
- var documentSerializationOptions = (options ?? DocumentSerializationOptions.Defaults) as DocumentSerializationOptions;
- if (documentSerializationOptions == null)
- {
- var message = string.Format(
- "Serialize method of BsonDocument expected serialization options of type {0}, not {1}.",
- BsonUtils.GetFriendlyTypeName(typeof(DocumentSerializationOptions)),
- BsonUtils.GetFriendlyTypeName(options.GetType()));
- throw new BsonSerializationException(message);
- }
-
- bsonWriter.WriteStartDocument();
- int idIndex;
- if (documentSerializationOptions.SerializeIdFirst && _indexes.TryGetValue("_id", out idIndex))
- {
- _elements[idIndex].WriteTo(bsonWriter);
- }
- else
- {
- idIndex = -1; // remember that when TryGetValue returns false it sets idIndex to 0
- }
-
- for (int i = 0; i < _elements.Count; i++)
- {
- // if serializeIdFirst is false then idIndex will be -1 and no elements will be skipped
- if (i != idIndex)
- {
- _elements[i].WriteTo(bsonWriter);
- }
- }
-
- bsonWriter.WriteEndDocument();
+ BsonDocumentSerializer.Instance.Serialize(bsonWriter, nominalType, this, options);
}
/// <summary>
@@ -1186,31 +1088,8 @@ public BsonDocument Set(string name, BsonValue value)
[Obsolete("SetDocumentId was intended to be private and will become private in a future release. Use document[\"_id\"] = value or document.Set(\"_id\", value) instead.")]
public void SetDocumentId(object id)
{
- if (id == null)
- {
- throw new ArgumentNullException("id");
- }
-
- // TODO: in a future release we will just cast directly to BsonValue because the caller is required to pass a BsonValue
- // var idBsonValue = (BsonValue)id;
-
- var idBsonValue = id as BsonValue;
- if (idBsonValue == null)
- {
- // SetDocumentId contract requires that caller provide an id of the correct type so this conversion is not correct
- // for temporary backward compatibility with versions prior to 1.4.2 we continue to map objects to BsonValue for now
- idBsonValue = BsonValue.Create(id); // TODO: in a future release this mapping will be removed
- }
-
- BsonElement idElement;
- if (TryGetElement("_id", out idElement))
- {
- idElement.Value = idBsonValue;
- }
- else
- {
- InsertAt(0, new BsonElement("_id", idBsonValue));
- }
+ var idProvider = (IBsonIdProvider)BsonDocumentSerializer.Instance;
+ idProvider.SetDocumentId(this, id);
}
/// <summary>
@@ -1348,44 +1227,51 @@ public bool TryGetValue(string name, out BsonValue value)
/// Writes the document to a BsonWriter.
/// </summary>
/// <param name="bsonWriter">The writer.</param>
+ [Obsolete("Use BsonSerializer.Serialize<BsonDocument> instead.")]
public new void WriteTo(BsonWriter bsonWriter)
{
- ((IBsonSerializable)this).Serialize(bsonWriter, typeof(BsonDocument), null);
+ BsonSerializer.Serialize(bsonWriter, this);
}
/// <summary>
/// Writes the document to a BsonBuffer.
/// </summary>
/// <param name="buffer">The buffer.</param>
+ [Obsolete("Use BsonSerializer.Serialize<BsonDocument> instead.")]
public void WriteTo(BsonBuffer buffer)
{
using (BsonWriter bsonWriter = BsonWriter.Create(buffer))
{
- WriteTo(bsonWriter);
+ BsonSerializer.Serialize(bsonWriter, this);
}
}
/// <summary>
/// Writes the document to a Stream.
/// </summary>
/// <param name="stream">The stream.</param>
+ [Obsolete("Use BsonSerializer.Serialize<BsonDocument> instead.")]
public void WriteTo(Stream stream)
{
using (BsonWriter bsonWriter = BsonWriter.Create(stream))
{
- WriteTo(bsonWriter);
+ BsonSerializer.Serialize(bsonWriter, this);
}
}
/// <summary>
/// Writes the document to a file.
/// </summary>
/// <param name="filename">The name of the file.</param>
+ [Obsolete("Use BsonSerializer.Serialize<BsonDocument> instead.")]
public void WriteTo(string filename)
{
using (FileStream stream = new FileStream(filename, FileMode.Create, FileAccess.Write))
{
- WriteTo(stream);
+ using (BsonWriter bsonWriter = BsonWriter.Create(stream))
+ {
+ BsonSerializer.Serialize(bsonWriter, this);
+ }
}
}
Oops, something went wrong.

0 comments on commit 5825955

Please sign in to comment.