Skip to content

Commit c20e2bb

Browse files
committed
CSHARP-5348: Add PopContext to Bson*Context where missing
1 parent e4b117b commit c20e2bb

6 files changed

+25
-10
lines changed

src/MongoDB.Bson/IO/BsonBinaryWriter.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public override void WriteEndArray()
290290
_bsonStream.WriteByte(0);
291291
BackpatchSize(); // size of document
292292

293-
_context = _context.ParentContext;
293+
_context = _context.PopContext();
294294
State = GetNextState();
295295
}
296296

@@ -313,7 +313,7 @@ public override void WriteEndDocument()
313313
_bsonStream.WriteByte(0);
314314
BackpatchSize(); // size of document
315315

316-
_context = _context.ParentContext;
316+
_context = _context.PopContext();
317317
if (_context == null)
318318
{
319319
State = BsonWriterState.Done;
@@ -323,7 +323,7 @@ public override void WriteEndDocument()
323323
if (_context.ContextType == ContextType.JavaScriptWithScope)
324324
{
325325
BackpatchSize(); // size of the JavaScript with scope value
326-
_context = _context.ParentContext;
326+
_context = _context.PopContext();
327327
}
328328
State = GetNextState();
329329
}

src/MongoDB.Bson/IO/BsonBinaryWriterContext.cs

+5
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,10 @@ internal int Index
5555
get { return _index; }
5656
set { _index = value; }
5757
}
58+
59+
internal BsonBinaryWriterContext PopContext()
60+
{
61+
return _parentContext;
62+
}
5863
}
5964
}

src/MongoDB.Bson/IO/BsonDocumentWriter.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public override void WriteEndArray()
195195

196196
base.WriteEndArray();
197197
var array = _context.Array;
198-
_context = _context.ParentContext;
198+
_context = _context.PopContext();
199199
WriteValue(array);
200200
State = GetNextState();
201201
}
@@ -219,15 +219,15 @@ public override void WriteEndDocument()
219219
if (_context.ContextType == ContextType.ScopeDocument)
220220
{
221221
var scope = _context.Document;
222-
_context = _context.ParentContext;
222+
_context = _context.PopContext();
223223
var code = _context.Code;
224-
_context = _context.ParentContext;
224+
_context = _context.PopContext();
225225
WriteValue(new BsonJavaScriptWithScope(code, scope));
226226
}
227227
else
228228
{
229229
var document = _context.Document;
230-
_context = _context.ParentContext;
230+
_context = _context.PopContext();
231231
if (_context != null)
232232
{
233233
WriteValue(document);

src/MongoDB.Bson/IO/BsonDocumentWriterContext.cs

+5
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,10 @@ internal string Code
8787
{
8888
get { return _code; }
8989
}
90+
91+
internal BsonDocumentWriterContext PopContext()
92+
{
93+
return _parentContext;
94+
}
9095
}
9196
}

src/MongoDB.Bson/IO/JsonWriter.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public override void WriteEndArray()
312312
base.WriteEndArray();
313313
_textWriter.Write("]");
314314

315-
_context = _context.ParentContext;
315+
_context = _context.PopContext();
316316
State = GetNextState();
317317
}
318318

@@ -344,12 +344,12 @@ public override void WriteEndDocument()
344344

345345
if (_context.ContextType == ContextType.ScopeDocument)
346346
{
347-
_context = _context.ParentContext;
347+
_context = _context.PopContext();
348348
WriteEndDocument();
349349
}
350350
else
351351
{
352-
_context = _context.ParentContext;
352+
_context = _context.PopContext();
353353
}
354354

355355
if (_context == null)

src/MongoDB.Bson/IO/JsonWriterContext.cs

+5
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,10 @@ internal bool HasElements
5252
get { return _hasElements; }
5353
set { _hasElements = value; }
5454
}
55+
56+
internal JsonWriterContext PopContext()
57+
{
58+
return _parentContext;
59+
}
5560
}
5661
}

0 commit comments

Comments
 (0)