You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixed CSHARP-446. BsonDocument methods GetDocumentId and SetDocumentId have been changed to be temporarily backward compatible with 1.4.0 and earlier. However, these methods were intended to be private, and all IBsonSerializable methods that were accidentally made public have been marked as deprecated and will be made private by explicit implementation in a future release.
@@ -793,16 +794,25 @@ public object Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializ
793
794
/// <param name="idNominalType">The nominal type of the Id.</param>
794
795
/// <param name="idGenerator">The IdGenerator for the Id (or null).</param>
795
796
/// <returns>True (a BsonDocument either has an Id member or one can be added).</returns>
797
+
[Obsolete("GetDocumentId was intended to be private and will become private in a future release. Use document[\"_id\"] or document.GetValue(\"_id\") instead.")]
@@ -1124,13 +1135,24 @@ public BsonDocument Set(string name, BsonValue value)
1124
1135
/// Sets the document Id.
1125
1136
/// </summary>
1126
1137
/// <param name="id">The value of the Id.</param>
1138
+
[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.")]
1127
1139
publicvoidSetDocumentId(objectid)
1128
1140
{
1129
1141
if(id==null)
1130
1142
{
1131
1143
thrownewArgumentNullException("id");
1132
1144
}
1133
-
varidBsonValue=(BsonValue)id;
1145
+
1146
+
// TODO: in a future release we will just cast directly to BsonValue because the caller is required to pass a BsonValue
1147
+
// var idBsonValue = (BsonValue)id;
1148
+
1149
+
varidBsonValue=idasBsonValue;
1150
+
if(idBsonValue==null)
1151
+
{
1152
+
// SetDocumentId contract requires that caller provide an id of the correct type so this conversion is not correct
1153
+
// for temporary backward compatibility with versions prior to 1.4.2 we continue to map objects to BsonValue for now
1154
+
idBsonValue=BsonValue.Create(id);// TODO: in a future release this mapping will be removed
1155
+
}
1134
1156
1135
1157
BsonElementidElement;
1136
1158
if(TryGetElement("_id",outidElement))
@@ -1280,7 +1302,7 @@ public bool TryGetValue(string name, out BsonValue value)
0 commit comments