public JsonReader( JsonBuffer buffer ) { this.buffer = buffer; this.context = new JsonReaderContext(null, ContextType.TopLevel); }
internal JsonReaderContext( JsonReaderContext parentContext, ContextType contextType ) { this.parentContext = parentContext; this.contextType = contextType; }
public JsonReaderContext Clone() { var clone = new JsonReaderContext(); clone.parentContext = this.parentContext; clone.contextType = this.contextType; return clone; }
// constructors /// <summary> /// Initializes a new instance of the JsonReader class. /// </summary> /// <param name="buffer">The buffer.</param> /// <param name="settings">The reader settings.</param> public JsonReader(JsonBuffer buffer, JsonReaderSettings settings) : base(settings) { _buffer = buffer; _jsonReaderSettings = settings; // already frozen by base class _context = new JsonReaderContext(null, ContextType.TopLevel); }
/// <summary> /// Initializes a new instance of the JsonReader class. /// </summary> /// <param name="buffer">The buffer.</param> public JsonReader( JsonBuffer buffer ) { this.buffer = buffer; this.context = new JsonReaderContext(null, ContextType.TopLevel); }
internal JsonReaderContext( JsonReaderContext parentContext, ContextType contextType ) { this.parentContext = parentContext; this.contextType = contextType; }
/// <summary> /// Initializes a new instance of the JsonReader class. /// </summary> /// <param name="buffer">The buffer.</param> /// <param name="settings">The reader settings.</param> public JsonReader( JsonBuffer buffer, JsonReaderSettings settings ) { this.buffer = buffer; this.settings = settings.Freeze(); this.context = new JsonReaderContext(null, ContextType.TopLevel); }
// constructors internal JsonReaderBookmark(BsonReaderState state, BsonType currentBsonType, string currentName, JsonReaderContext context, JsonToken currentToken, BsonValue currentValue, JsonToken pushedToken, int position) : base(state, currentBsonType, currentName) { this.context = context.Clone(); this.currentToken = currentToken; this.currentValue = currentValue; this.pushedToken = pushedToken; this.position = position; }
/// <summary> /// Initializes a new instance of the JsonReader class. /// </summary> /// <param name="buffer">The buffer.</param> /// <param name="settings">The reader settings.</param> public JsonReader( JsonBuffer buffer, JsonReaderSettings settings ) { this.buffer = buffer; this.settings = settings.Freeze(); this.context = new JsonReaderContext(null, ContextType.TopLevel); }
// constructors internal JsonReaderBookmark(BsonReaderState state, BsonType currentBsonType, string currentName, JsonReaderContext context, JsonToken currentToken, BsonValue currentValue, JsonToken pushedToken, int position) : base(state, currentBsonType, currentName) { _context = context.Clone(); _currentToken = currentToken; _currentValue = currentValue; _pushedToken = pushedToken; _position = position; }
/// <summary> /// Reads the start of a BSON document. /// </summary> public override void ReadStartDocument() { if (disposed) { ThrowObjectDisposedException(); } VerifyBsonType("ReadStartDocument", BsonType.Document); context = new JsonReaderContext(context, ContextType.Document); state = BsonReaderState.Type; }
/// <summary> /// Reads a BSON JavaScript with scope from the reader (call ReadStartDocument next to read the scope). /// </summary> /// <returns>A string.</returns> public override string ReadJavaScriptWithScope() { if (disposed) { ThrowObjectDisposedException(); } VerifyBsonType("ReadJavaScriptWithScope", BsonType.JavaScriptWithScope); context = new JsonReaderContext(context, ContextType.JavaScriptWithScope); state = BsonReaderState.ScopeDocument; return(currentValue.AsString); }
/// <summary> /// Reads the end of a BSON document from the reader. /// </summary> public override void ReadEndDocument() { if (disposed) { ThrowObjectDisposedException(); } if ( context.ContextType != ContextType.Document && context.ContextType != ContextType.ScopeDocument ) { var message = string.Format("ReadEndDocument cannot be called when ContextType is: {0}", context.ContextType); throw new InvalidOperationException(message); } if (state == BsonReaderState.Type) { ReadBsonType(); // will set state to EndOfDocument if at end of document } if (state != BsonReaderState.EndOfDocument) { var message = string.Format("ReadEndDocument cannot be called when State is: {0}", state); throw new InvalidOperationException(message); } context = context.PopContext(); if (context != null && context.ContextType == ContextType.JavaScriptWithScope) { context = context.PopContext(); // JavaScriptWithScope VerifyToken("}"); // outermost closing bracket for JavaScriptWithScope } switch (context.ContextType) { case ContextType.Array: state = BsonReaderState.Type; break; case ContextType.Document: state = BsonReaderState.Type; break; case ContextType.TopLevel: state = BsonReaderState.Done; break; default: throw new BsonInternalException("Unexpected ContextType"); } if (context.ContextType == ContextType.Array || context.ContextType == ContextType.Document) { var commaToken = PopToken(); if (commaToken.Type != JsonTokenType.Comma) { PushToken(commaToken); } } }
/// <summary> /// Returns the reader to previously bookmarked position and state. /// </summary> /// <param name="bookmark">The bookmark.</param> public override void ReturnToBookmark( BsonReaderBookmark bookmark ) { var jsonReaderBookmark = (JsonReaderBookmark)bookmark; state = jsonReaderBookmark.State; currentBsonType = jsonReaderBookmark.CurrentBsonType; currentName = jsonReaderBookmark.CurrentName; context = jsonReaderBookmark.CloneContext(); currentToken = jsonReaderBookmark.CurrentToken; currentValue = jsonReaderBookmark.CurrentValue; pushedToken = jsonReaderBookmark.PushedToken; buffer.Position = jsonReaderBookmark.Position; }
/// <summary> /// Returns the reader to previously bookmarked position and state. /// </summary> /// <param name="bookmark">The bookmark.</param> public override void ReturnToBookmark( BsonReaderBookmark bookmark ) { if (disposed) { ThrowObjectDisposedException(); } var jsonReaderBookmark = (JsonReaderBookmark)bookmark; state = jsonReaderBookmark.State; currentBsonType = jsonReaderBookmark.CurrentBsonType; currentName = jsonReaderBookmark.CurrentName; context = jsonReaderBookmark.CloneContext(); currentToken = jsonReaderBookmark.CurrentToken; currentValue = jsonReaderBookmark.CurrentValue; pushedToken = jsonReaderBookmark.PushedToken; buffer.Position = jsonReaderBookmark.Position; }
/// <summary> /// Reads the end of a BSON array from the reader. /// </summary> public override void ReadEndArray() { if (disposed) { ThrowObjectDisposedException(); } if (context.ContextType != ContextType.Array) { var message = string.Format("ReadEndArray cannot be called when ContextType is: {0}", context.ContextType); throw new InvalidOperationException(message); } if (state == BsonReaderState.Type) { ReadBsonType(); // will set state to EndOfArray if at end of array } if (state != BsonReaderState.EndOfArray) { var message = string.Format("ReadEndArray cannot be called when State is: {0}", state); throw new InvalidOperationException(message); } context = context.PopContext(); switch (context.ContextType) { case ContextType.Array: state = BsonReaderState.Type; break; case ContextType.Document: state = BsonReaderState.Type; break; case ContextType.TopLevel: state = BsonReaderState.Done; break; default: throw new BsonInternalException("Unexpected ContextType"); } if (context.ContextType == ContextType.Array || context.ContextType == ContextType.Document) { var commaToken = PopToken(); if (commaToken.Type != JsonTokenType.Comma) { PushToken(commaToken); } } }
/// <summary> /// Reads the end of a BSON array from the reader. /// </summary> public override void ReadEndArray() { if (disposed) { ThrowObjectDisposedException(); } if (context.ContextType != ContextType.Array) { ThrowInvalidContextType("ReadEndArray", context.ContextType, ContextType.Array); } if (state == BsonReaderState.Type) { ReadBsonType(); // will set state to EndOfArray if at end of array } if (state != BsonReaderState.EndOfArray) { ThrowInvalidState("ReadEndArray", BsonReaderState.EndOfArray); } context = context.PopContext(); switch (context.ContextType) { case ContextType.Array: state = BsonReaderState.Type; break; case ContextType.Document: state = BsonReaderState.Type; break; case ContextType.TopLevel: state = BsonReaderState.Done; break; default: throw new BsonInternalException("Unexpected ContextType."); } if (context.ContextType == ContextType.Array || context.ContextType == ContextType.Document) { var commaToken = PopToken(); if (commaToken.Type != JsonTokenType.Comma) { PushToken(commaToken); } } }
/// <summary> /// Returns the reader to previously bookmarked position and state. /// </summary> /// <param name="bookmark">The bookmark.</param> public override void ReturnToBookmark( BsonReaderBookmark bookmark ) { if (disposed) { ThrowObjectDisposedException(); } var jsonReaderBookmark = (JsonReaderBookmark) bookmark; state = jsonReaderBookmark.State; currentBsonType = jsonReaderBookmark.CurrentBsonType; currentName = jsonReaderBookmark.CurrentName; context = jsonReaderBookmark.CloneContext(); currentToken = jsonReaderBookmark.CurrentToken; currentValue = jsonReaderBookmark.CurrentValue; pushedToken = jsonReaderBookmark.PushedToken; buffer.Position = jsonReaderBookmark.Position; }
/// <summary> /// Reads the start of a BSON document. /// </summary> public override void ReadStartDocument() { if (disposed) { ThrowObjectDisposedException(); } VerifyBsonType("ReadStartDocument", BsonType.Document); context = new JsonReaderContext(context, ContextType.Document); state = BsonReaderState.Type; }
/// <summary> /// Reads a BSON JavaScript with scope from the reader (call ReadStartDocument next to read the scope). /// </summary> /// <returns>A string.</returns> public override string ReadJavaScriptWithScope() { if (disposed) { ThrowObjectDisposedException(); } VerifyBsonType("ReadJavaScriptWithScope", BsonType.JavaScriptWithScope); context = new JsonReaderContext(context, ContextType.JavaScriptWithScope); state = BsonReaderState.ScopeDocument; return currentValue.AsString; }
/// <summary> /// Reads the end of a BSON document from the reader. /// </summary> public override void ReadEndDocument() { if (disposed) { ThrowObjectDisposedException(); } if ( context.ContextType != ContextType.Document && context.ContextType != ContextType.ScopeDocument ) { ThrowInvalidContextType("ReadEndDocument", context.ContextType, ContextType.Document, ContextType.ScopeDocument); } if (state == BsonReaderState.Type) { ReadBsonType(); // will set state to EndOfDocument if at end of document } if (state != BsonReaderState.EndOfDocument) { ThrowInvalidState("ReadEndDocument", BsonReaderState.EndOfDocument); } context = context.PopContext(); if (context != null && context.ContextType == ContextType.JavaScriptWithScope) { context = context.PopContext(); // JavaScriptWithScope VerifyToken("}"); // outermost closing bracket for JavaScriptWithScope } switch (context.ContextType) { case ContextType.Array: state = BsonReaderState.Type; break; case ContextType.Document: state = BsonReaderState.Type; break; case ContextType.TopLevel: state = BsonReaderState.Done; break; default: throw new BsonInternalException("Unexpected ContextType"); } if (context.ContextType == ContextType.Array || context.ContextType == ContextType.Document) { var commaToken = PopToken(); if (commaToken.Type != JsonTokenType.Comma) { PushToken(commaToken); } } }
/// <summary> /// Reads the end of a BSON array from the reader. /// </summary> public override void ReadEndArray() { if (disposed) { ThrowObjectDisposedException(); } if (context.ContextType != ContextType.Array) { ThrowInvalidContextType("ReadEndArray", context.ContextType, ContextType.Array); } if (state == BsonReaderState.Type) { ReadBsonType(); // will set state to EndOfArray if at end of array } if (state != BsonReaderState.EndOfArray) { ThrowInvalidState("ReadEndArray", BsonReaderState.EndOfArray); } context = context.PopContext(); switch (context.ContextType) { case ContextType.Array: state = BsonReaderState.Type; break; case ContextType.Document: state = BsonReaderState.Type; break; case ContextType.TopLevel: state = BsonReaderState.Done; break; default: throw new BsonInternalException("Unexpected ContextType."); } if (context.ContextType == ContextType.Array || context.ContextType == ContextType.Document) { var commaToken = PopToken(); if (commaToken.Type != JsonTokenType.Comma) { PushToken(commaToken); } } }
/// <summary> /// Reads the start of a BSON array. /// </summary> public override void ReadStartArray() { if (_disposed) { ThrowObjectDisposedException(); } VerifyBsonType("ReadStartArray", BsonType.Array); _context = new JsonReaderContext(_context, ContextType.Array); _state = BsonReaderState.Type; }
internal JsonReaderContext(JsonReaderContext parentContext, ContextType contextType) { _parentContext = parentContext; _contextType = contextType; }
internal JsonReaderContext(JsonReaderContext parentContext, ContextType contextType) { _parentContext = parentContext; _contextType = contextType; }
public override void ReturnToBookmark( BsonReaderBookmark bookmark ) { var jsonReaderBookmark = (JsonReaderBookmark) bookmark; state = jsonReaderBookmark.State; currentBsonType = jsonReaderBookmark.CurrentBsonType; currentName = jsonReaderBookmark.CurrentName; context = jsonReaderBookmark.Context; currentToken = jsonReaderBookmark.CurrentToken; currentValue = jsonReaderBookmark.CurrentValue; pushedToken = jsonReaderBookmark.PushedToken; buffer.Position = jsonReaderBookmark.Position; }
public override void ReadEndArray() { if (disposed) { ThrowObjectDisposedException(); } if (context.ContextType != ContextType.Array) { var message = string.Format("ReadEndArray cannot be called when ContextType is: {0}", context.ContextType); throw new InvalidOperationException(message); } if (state == BsonReaderState.Type) { ReadBsonType(); // will set state to EndOfArray if at end of array } if (state != BsonReaderState.EndOfArray) { var message = string.Format("ReadEndArray cannot be called when State is: {0}", state); throw new InvalidOperationException(message); } context = context.PopContext(); switch (context.ContextType) { case ContextType.Array: state = BsonReaderState.Type; break; case ContextType.Document: state = BsonReaderState.Type; break; case ContextType.TopLevel: state = BsonReaderState.Done; break; default: throw new BsonInternalException("Unexpected ContextType"); } if (context.ContextType == ContextType.Array || context.ContextType == ContextType.Document) { var commaToken = PopToken(); if (commaToken.Type != JsonTokenType.Comma) { PushToken(commaToken); } } }