1717using System . Collections . Generic ;
1818using System . Globalization ;
1919using System . IO ;
20- using System . Linq ;
2120
2221namespace MongoDB . Bson . IO
2322{
@@ -32,7 +31,7 @@ public class BsonBinaryReader : BsonReader
3231#pragma warning restore CA2213 // Disposable never disposed
3332 private readonly BsonStream _bsonStream ;
3433 private BsonBinaryReaderContext _context ;
35- private readonly Stack < BsonBinaryReaderContext > _contexts = new ( 4 ) ;
34+ private readonly Stack < BsonBinaryReaderContext > _contextStack = new ( 4 ) ;
3635
3736 // constructors
3837 /// <summary>
@@ -113,7 +112,7 @@ public override void Close()
113112 /// </summary>
114113 /// <returns>A bookmark.</returns>
115114 public override BsonReaderBookmark GetBookmark ( ) =>
116- new BsonBinaryReaderBookmark ( State , CurrentBsonType , CurrentName , _context , _contexts , _bsonStream . Position ) ;
115+ new BsonBinaryReaderBookmark ( State , CurrentBsonType , CurrentName , _context , _contextStack , _bsonStream . Position ) ;
117116
118117 /// <summary>
119118 /// Determines whether this reader is at end of file.
@@ -673,7 +672,7 @@ public override void ReturnToBookmark(BsonReaderBookmark bookmark)
673672 State = binaryReaderBookmark . State ;
674673 CurrentBsonType = binaryReaderBookmark . CurrentBsonType ;
675674 CurrentName = binaryReaderBookmark . CurrentName ;
676- _context = binaryReaderBookmark . RestoreContext ( _contexts ) ;
675+ _context = binaryReaderBookmark . RestoreContext ( _contextStack ) ;
677676 _bsonStream . Position = binaryReaderBookmark . Position ;
678677 }
679678
@@ -782,7 +781,7 @@ private string GenerateDottedElementName()
782781 elementName = "?" ;
783782 }
784783
785- return GenerateDottedElementName ( _contexts . ToArray ( ) , 0 , elementName ) ;
784+ return GenerateDottedElementName ( _contextStack . ToArray ( ) , 0 , elementName ) ;
786785 }
787786
788787 private string GenerateDottedElementName ( BsonBinaryReaderContext [ ] contexts , int currentContextIndex , string elementName )
@@ -827,6 +826,23 @@ private BsonReaderState GetNextState()
827826 }
828827 }
829828
829+ private void PopContext ( )
830+ {
831+ var actualSize = _bsonStream . Position - _context . StartPosition ;
832+ if ( actualSize != _context . Size )
833+ {
834+ throw new FormatException ( $ "Expected size to be { _context . Size } , not { actualSize } .") ;
835+ }
836+
837+ _context = _contextStack . Pop ( ) ;
838+ }
839+
840+ private void PushContext ( BsonBinaryReaderContext newContext )
841+ {
842+ _contextStack . Push ( _context ) ;
843+ _context = newContext ;
844+ }
845+
830846 private int ReadSize ( )
831847 {
832848 int size = _bsonStream . ReadInt32 ( ) ;
@@ -842,22 +858,5 @@ private int ReadSize()
842858 }
843859 return size ;
844860 }
845-
846- private void PopContext ( )
847- {
848- var actualSize = _bsonStream . Position - _context . StartPosition ;
849- if ( actualSize != _context . Size )
850- {
851- throw new FormatException ( $ "Expected size to be { _context . Size } , not { actualSize } .") ;
852- }
853-
854- _context = _contexts . Pop ( ) ;
855- }
856-
857- private void PushContext ( BsonBinaryReaderContext newContext )
858- {
859- _contexts . Push ( _context ) ;
860- _context = newContext ;
861- }
862861 }
863862}
0 commit comments