Skip to content

Commit 448122f

Browse files
author
rstam
committed
Merge commit '29672a' into csharp452
2 parents 2a6e37d + 29672a7 commit 448122f

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
lines changed

Bson/Serialization/BsonClassMapSerializer.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public object Deserialize(
195195
for (;;)
196196
{
197197
// examine missing elements (memberMapBlock is shifted right as we work through the block)
198-
while ((memberMapBlock & 1) != 0)
198+
for (; (memberMapBlock & 1) != 0; ++memberMapIndex, memberMapBlock >>= 1)
199199
{
200200
var memberMap = allMemberMaps[memberMapIndex];
201201
if (memberMap.IsReadOnly)
@@ -212,9 +212,6 @@ public object Deserialize(
212212
throw new FileFormatException(message);
213213
}
214214
memberMap.ApplyDefaultValue(obj);
215-
216-
++memberMapIndex;
217-
memberMapBlock >>= 1;
218215
}
219216

220217
if (memberMapBlock == 0)

BsonUnitTests/BsonUnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
<Compile Include="Jira\CSharp369Tests.cs" />
146146
<Compile Include="Jira\CSharp400Tests.cs" />
147147
<Compile Include="Jira\CSharp446Tests.cs" />
148+
<Compile Include="Jira\CSharp452Tests.cs" />
148149
<Compile Include="Jira\CSharp70Tests.cs" />
149150
<Compile Include="Jira\CSharp71Tests.cs" />
150151
<Compile Include="Jira\CSharp74Tests.cs" />

BsonUnitTests/Jira/CSharp452Tests.cs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/* Copyright 2010-2012 10gen Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System;
17+
using System.Linq;
18+
using NUnit.Framework;
19+
20+
using MongoDB.Bson;
21+
using MongoDB.Bson.Serialization;
22+
using MongoDB.Bson.Serialization.Attributes;
23+
24+
namespace MongoDB.BsonUnitTests.Jira
25+
{
26+
[TestFixture]
27+
public class CSharp452Tests
28+
{
29+
public class A
30+
{
31+
private static readonly DateTime __staticTime = DateTime.UtcNow;
32+
33+
[BsonElement("a", Order = 0)]
34+
[BsonIgnoreIfDefault]
35+
public DateTime DateTime1
36+
{
37+
get;
38+
set;
39+
}
40+
41+
[BsonElement("b", Order = 1)]
42+
[BsonIgnoreIfDefault]
43+
public DateTime DateTime2
44+
{
45+
get
46+
{
47+
return __staticTime;
48+
}
49+
}
50+
51+
[BsonElement("c", Order = 2)]
52+
[BsonIgnoreIfDefault]
53+
public DateTime DateTime3
54+
{
55+
get
56+
{
57+
return DateTime.MinValue;
58+
}
59+
}
60+
}
61+
62+
[Test]
63+
public void TestReadonlyMembers()
64+
{
65+
var document = new A
66+
{
67+
DateTime1 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc),
68+
};
69+
70+
var bson = document.ToBson();
71+
var rehydrated = BsonSerializer.Deserialize<A>(bson);
72+
Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)