Permalink
Browse files

CSHARP-559: deprecate RawValue and RawValues properties from the Bson…

…Document object model.
  • Loading branch information...
1 parent 340ff92 commit 0c160bc3e3d9fbc972482f8d2babeab21fc243dc rstam committed Dec 5, 2012
@@ -195,6 +195,7 @@ public bool IsReadOnly
/// <summary>
/// Gets the array elements as raw values (see BsonValue.RawValue).
/// </summary>
+ [Obsolete("Use ToArray to ToList instead.")]
public IEnumerable<object> RawValues
{
get { return _values.Select(v => v.RawValue); }
@@ -679,6 +680,7 @@ public void CopyTo(BsonValue[] array, int arrayIndex)
/// </summary>
/// <param name="array">The other array.</param>
/// <param name="arrayIndex">The zero based index of the other array at which to start copying.</param>
+ [Obsolete("Use ToArray or ToList instead.")]
public void CopyTo(object[] array, int arrayIndex)
{
for (int i = 0, j = arrayIndex; i < _values.Count; i++, j++)
@@ -137,6 +137,7 @@ public GuidRepresentation GuidRepresentation
/// Gets the BsonBinaryData as a Guid if the subtype is UuidStandard or UuidLegacy, otherwise null.
/// </summary>
#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary
+ [Obsolete("Use Value instead.")]
public override object RawValue
{
get
@@ -66,6 +66,7 @@ public static BsonBoolean True
/// <summary>
/// Gets the BsonBoolean as a bool.
/// </summary>
+ [Obsolete("Use Value instead.")]
public override object RawValue
{
get { return _value; }
@@ -76,6 +76,7 @@ public long MillisecondsSinceEpoch
/// <summary>
/// Gets the number of milliseconds since the Unix Epoch.
/// </summary>
+ [Obsolete("Use MillisecondsSinceEpoch instead.")]
public override object RawValue
{
get { return _millisecondsSinceEpoch; }
@@ -232,6 +232,7 @@ public IEnumerable<string> Names
/// <summary>
/// Gets the raw values (see BsonValue.RawValue).
/// </summary>
+ [Obsolete("Use Values instead.")]
public IEnumerable<object> RawValues
{
get { return _elements.Select(e => e.Value.RawValue); }
@@ -46,6 +46,7 @@ public BsonDouble(double value)
/// <summary>
/// Gets the BsonDouble as a double.
/// </summary>
+ [Obsolete("Use Value instead.")]
public override object RawValue
{
get { return _value; }
@@ -91,6 +91,7 @@ public static BsonInt32 Three
/// <summary>
/// Gets the BsonInt32 as an int.
/// </summary>
+ [Obsolete("Use Value instead.")]
public override object RawValue
{
get { return _value; }
@@ -45,6 +45,7 @@ public BsonInt64(long value)
/// <summary>
/// Gets the BsonInt64 as a long.
/// </summary>
+ [Obsolete("Use Value instead.")]
public override object RawValue
{
get { return _value; }
@@ -145,6 +145,7 @@ public DateTime CreationTime
/// <summary>
/// Gets the BsonObjectId as an ObjectId.
/// </summary>
+ [Obsolete("Use Value instead.")]
public override object RawValue
{
get { return _value; }
@@ -61,6 +61,7 @@ public static BsonString Empty
/// <summary>
/// Gets the BsonString as a string.
/// </summary>
+ [Obsolete("Use Value instead.")]
public override object RawValue
{
get { return _value; }
@@ -538,6 +538,7 @@ public bool IsString
/// Gets the raw value of this BsonValue (or null if this BsonValue doesn't have a single scalar value).
/// </summary>
// note: don't change return value to "this" or lots of things will break
+ [Obsolete("Use Value property of subclasses or BsonTypeMapper.MapToDotNetValue instead.")]
public virtual object RawValue
{
get { return null; } // subclasses that have a single value (e.g. Int32) override this
@@ -123,7 +123,9 @@ public void TestMillisecondsSinceEpochValues()
{
var bsonDateTime = new BsonDateTime(value);
Assert.AreEqual(value, bsonDateTime.MillisecondsSinceEpoch);
+#pragma warning disable 618
Assert.AreEqual(value, bsonDateTime.RawValue);
+#pragma warning restore
}
}
@@ -227,7 +227,9 @@ public void TestCopyToOjbectArray()
{
var bsonArray = new BsonArray { 1, 2 };
var bsonValueArray = new object[2];
+#pragma warning disable 618
bsonArray.CopyTo(bsonValueArray, 0);
+#pragma warning restore
Assert.AreEqual(1, bsonValueArray[0]);
Assert.AreEqual(2, bsonValueArray[1]);
}
@@ -630,7 +632,9 @@ public void TestRawValues()
{
var array = new BsonArray { 1, "abc", new BsonDocument("x", 1) };
var expectedRawValues = new object[] { 1, "abc", null };
+#pragma warning disable 618
Assert.IsTrue(expectedRawValues.SequenceEqual(array.RawValues));
+#pragma warning restore
}
[Test]
@@ -36,7 +36,9 @@ public void TestGuidCSharpLegacy()
Assert.AreEqual(BsonBinarySubType.UuidLegacy, binaryData.SubType);
Assert.AreEqual(GuidRepresentation.CSharpLegacy, binaryData.GuidRepresentation);
Assert.AreEqual(guid, binaryData.AsGuid);
+#pragma warning disable 618
Assert.AreEqual(guid, binaryData.RawValue);
+#pragma warning restore
}
[Test]
@@ -49,7 +51,9 @@ public void TestGuidPythonLegacy()
Assert.AreEqual(BsonBinarySubType.UuidLegacy, binaryData.SubType);
Assert.AreEqual(GuidRepresentation.PythonLegacy, binaryData.GuidRepresentation);
Assert.AreEqual(guid, binaryData.AsGuid);
+#pragma warning disable 618
Assert.AreEqual(guid, binaryData.RawValue);
+#pragma warning restore
}
[Test]
@@ -62,7 +66,9 @@ public void TestGuidJavaLegacy()
Assert.AreEqual(BsonBinarySubType.UuidLegacy, binaryData.SubType);
Assert.AreEqual(GuidRepresentation.JavaLegacy, binaryData.GuidRepresentation);
Assert.AreEqual(guid, binaryData.AsGuid);
+#pragma warning disable 618
Assert.AreEqual(guid, binaryData.RawValue);
+#pragma warning restore
}
}
}
@@ -312,8 +312,10 @@ public void TestConstructorNoArgs()
Assert.AreEqual(false, document.IsBsonArray);
Assert.AreEqual(true, document.IsBsonDocument);
Assert.AreEqual(0, document.Names.Count());
+#pragma warning disable 618
Assert.AreEqual(null, document.RawValue);
Assert.AreEqual(0, document.RawValues.Count());
+#pragma warning restore
Assert.AreEqual(true, document.ToBoolean());
Assert.AreSame(document, document.ToBsonDocument());
Assert.AreEqual("{ }", document.ToJson());
@@ -1711,13 +1711,16 @@ private string GetIndexName(BsonDocument keys, BsonDocument options)
sb.Append(element.Name);
sb.Append("_");
var value = element.Value;
- if (value.BsonType == BsonType.Int32 ||
- value.BsonType == BsonType.Int64 ||
- value.BsonType == BsonType.Double ||
- value.BsonType == BsonType.String)
+ string valueString;
+ switch (value.BsonType)
{
- sb.Append(value.RawValue.ToString().Replace(' ', '_'));
+ case BsonType.Int32: valueString = ((BsonInt32)value).Value.ToString(); break;
+ case BsonType.Int64: valueString = ((BsonInt64)value).Value.ToString(); break;
+ case BsonType.Double: valueString = ((BsonDouble)value).Value.ToString(); break;
+ case BsonType.String: valueString = ((BsonString)value).Value; break;
+ default: valueString = "x"; break;
}
+ sb.Append(valueString.Replace(' ', '_'));
}
return sb.ToString();
}

0 comments on commit 0c160bc

Please sign in to comment.