public BonValue Read() { try { BonValueType type = (BonValueType)br.ReadByte(); switch (type) { case BonValueType.Array: return(ReadArray()); case BonValueType.Document: return(ReadDoc()); case BonValueType.Binary: return(ReadBinary()); case BonValueType.Boolean: { BonBoolean v = new BonBoolean(br.ReadByte() != 0); return(v); } case BonValueType.Double: { BonDouble v = new BonDouble(br.ReadDouble()); return(v); } case BonValueType.Float: { BonFloat v = new BonFloat(br.ReadSingle()); return(v); } case BonValueType.Int: { BonInt v = new BonInt(br.ReadInt32()); return(v); } case BonValueType.Long: { BonLong v = new BonLong(br.ReadInt64()); return(v); } case BonValueType.Null: return(BonNull.value); case BonValueType.String: { BonString v = new BonString(br.ReadString()); return(v); } default: return(null); } } catch (Exception e) { throw SyntaxError(e.Message); } }
private BonValue NextNumber() { myIndex--; int startIndex = myIndex; while (true) { char c = Next(); if ((c >= '0' && c <= '9') || c == '.' || c == '-' || c == '+' || c == 'e' || c == 'E') { continue; } break; } myIndex--; string s = new string(mySource, startIndex, myIndex - startIndex); if (s.IndexOfAny(doubleTip) >= 0) { double d; if (double.TryParse(s, out d)) { BonDouble v = new BonDouble(d); return(v); } throw SyntaxError("Cast Double error"); } int i; if (int.TryParse(s, out i)) { BonInt v = new BonInt(i); return(v); } long l; if (long.TryParse(s, out l)) { BonLong v = new BonLong(l); return(v); } throw SyntaxError("Cast Int32 error"); }