/// <summary> /// Reads a BsonType from the reader. /// </summary> /// <returns>A BsonType.</returns> public override BsonType ReadBsonType() { if (Disposed) { ThrowObjectDisposedException(); } if (State == BsonReaderState.Initial || State == BsonReaderState.ScopeDocument) { // there is an implied type of Document for the top level and for scope documents CurrentBsonType = BsonType.Document; State = BsonReaderState.Value; return(CurrentBsonType); } if (State != BsonReaderState.Type) { ThrowInvalidState("ReadBsonType", BsonReaderState.Type); } CurrentBsonType = _bsonStream.ReadBsonType(); if (CurrentBsonType == BsonType.EndOfDocument) { switch (_context.ContextType) { case ContextType.Array: State = BsonReaderState.EndOfArray; return(BsonType.EndOfDocument); case ContextType.Document: case ContextType.ScopeDocument: State = BsonReaderState.EndOfDocument; return(BsonType.EndOfDocument); default: var message = string.Format("BsonType EndOfDocument is not valid when ContextType is {0}.", _context.ContextType); throw new FormatException(message); } } else { switch (_context.ContextType) { case ContextType.Array: _bsonStream.SkipCString(); // ignore array element names State = BsonReaderState.Value; break; case ContextType.Document: case ContextType.ScopeDocument: State = BsonReaderState.Name; break; default: throw new BsonInternalException("Unexpected ContextType."); } return(CurrentBsonType); } }
static int _m_SkipCString(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); MongoDB.Bson.IO.BsonStream gen_to_be_invoked = (MongoDB.Bson.IO.BsonStream)translator.FastGetCSObj(L, 1); { gen_to_be_invoked.SkipCString( ); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
/// <summary> /// Reads a BsonType from the reader. /// </summary> /// <returns>A BsonType.</returns> public override BsonType ReadBsonType() { if (Disposed) { ThrowObjectDisposedException(); } if (State == BsonReaderState.Initial || State == BsonReaderState.ScopeDocument) { // there is an implied type of Document for the top level and for scope documents CurrentBsonType = BsonType.Document; State = BsonReaderState.Value; return(CurrentBsonType); } if (State != BsonReaderState.Type) { ThrowInvalidState("ReadBsonType", BsonReaderState.Type); } if (_context.ContextType == ContextType.Array) { _context.CurrentArrayIndex++; } try { CurrentBsonType = _bsonStream.ReadBsonType(); } catch (FormatException ex) { if (ex.Message.StartsWith("Detected unknown BSON type")) { // insert the element name into the error message var periodIndex = ex.Message.IndexOf('.'); var dottedElementName = GenerateDottedElementName(); var message = ex.Message.Substring(0, periodIndex) + $" for fieldname \"{dottedElementName}\"" + ex.Message.Substring(periodIndex); throw new FormatException(message); } throw; } if (CurrentBsonType == BsonType.EndOfDocument) { switch (_context.ContextType) { case ContextType.Array: State = BsonReaderState.EndOfArray; return(BsonType.EndOfDocument); case ContextType.Document: case ContextType.ScopeDocument: State = BsonReaderState.EndOfDocument; return(BsonType.EndOfDocument); default: var message = string.Format("BsonType EndOfDocument is not valid when ContextType is {0}.", _context.ContextType); throw new FormatException(message); } } else { switch (_context.ContextType) { case ContextType.Array: _bsonStream.SkipCString(); // ignore array element names State = BsonReaderState.Value; break; case ContextType.Document: case ContextType.ScopeDocument: State = BsonReaderState.Name; break; default: throw new BsonInternalException("Unexpected ContextType."); } return(CurrentBsonType); } }