// public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(BsonSymbol));

            var bsonType = bsonReader.GetCurrentBsonType();
            switch (bsonType)
            {
                case BsonType.Symbol:
                    return BsonSymbolTable.Lookup(bsonReader.ReadSymbol());
                default:
                    var message = string.Format("Cannot deserialize BsonSymbol from BsonType {0}.", bsonType);
                    throw new FileFormatException(message);
            }
        }
        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(string));
            var representationSerializationOptions = EnsureSerializationOptions<RepresentationSerializationOptions>(options);

            var bsonType = bsonReader.GetCurrentBsonType();
            if (bsonType == BsonType.Null)
            {
                bsonReader.ReadNull();
                return null;
            }
            else
            {
                switch (bsonType)
                {
                    case BsonType.ObjectId:
                        if (representationSerializationOptions.Representation == BsonType.ObjectId)
                        {
                            int timestamp, machine, increment;
                            short pid;
                            bsonReader.ReadObjectId(out timestamp, out machine, out pid, out increment);
                            var objectId = new ObjectId(timestamp, machine, pid, increment);
                            return objectId.ToString();
                        }
                        else
                        {
                            goto default;
                        }
                    case BsonType.String:
                        return bsonReader.ReadString();
                    case BsonType.Symbol:
                        return bsonReader.ReadSymbol();
                    default:
                        var message = string.Format("Cannot deserialize string from BsonType {0}.", bsonType);
                        throw new FileFormatException(message);
                }
            }
        }
 public void TestSymbol() {
     var json = "{ \"$symbol\" : \"symbol\" }";
     using (bsonReader = BsonReader.Create(json)) {
         Assert.AreEqual(BsonType.Symbol, bsonReader.ReadBsonType());
         Assert.AreEqual("symbol", bsonReader.ReadSymbol());
         Assert.AreEqual(BsonReaderState.Done, bsonReader.State);
     }
     Assert.AreEqual(json, BsonSerializer.Deserialize<BsonSymbol>(new StringReader(json)).ToJson());
 }
 /// <summary>
 /// Deserializes an object from a BsonReader.
 /// </summary>
 /// <param name="bsonReader">The BsonReader.</param>
 /// <param name="nominalType">The nominal type of the object.</param>
 /// <param name="options">The serialization options.</param>
 /// <returns>An object.</returns>
 public override object Deserialize(
     BsonReader bsonReader,
     Type nominalType,
     IBsonSerializationOptions options
 ) {
     var bsonType = bsonReader.CurrentBsonType;
     switch (bsonType) {
         case BsonType.Null:
             bsonReader.ReadNull();
             return null;
         case BsonType.String:
             return BsonSymbol.Create(bsonReader.ReadString());
         case BsonType.Symbol:
             return BsonSymbol.Create(bsonReader.ReadSymbol());
         default:
             var message = string.Format("Cannot deserialize BsonSymbol from BsonType {0}.", bsonType);
             throw new FileFormatException(message);
     }
 }
 /// <summary>
 /// Deserializes an object from a BsonReader.
 /// </summary>
 /// <param name="bsonReader">The BsonReader.</param>
 /// <param name="nominalType">The nominal type of the object.</param>
 /// <param name="options">The serialization options.</param>
 /// <returns>An object.</returns>
 public override object Deserialize(
     BsonReader bsonReader,
     Type nominalType,
     IBsonSerializationOptions options
 ) {
     var bsonType = bsonReader.CurrentBsonType;
     if (bsonType == BsonType.Null) {
         bsonReader.ReadNull();
         return null;
     } else {
         var representation = (options == null) ? BsonType.String : ((RepresentationSerializationOptions) options).Representation;
         switch (representation) {
             case BsonType.ObjectId:
                 int timestamp, machine, increment;
                 short pid;
                 bsonReader.ReadObjectId(out timestamp, out machine, out pid, out increment);
                 var objectId = new ObjectId(timestamp, machine, pid, increment);
                 return objectId.ToString();
             case BsonType.String:
                 return bsonReader.ReadString();
             case BsonType.Symbol:
                 return bsonReader.ReadSymbol();
             default:
                 var message = string.Format("Cannot deserialize string from BsonType: {0}", bsonType);
                 throw new FileFormatException(message);
         }
     }
 }
 public override object Deserialize(
     BsonReader bsonReader,
     Type nominalType
 )
 {
     var bsonType = bsonReader.CurrentBsonType;
     if (bsonType == BsonType.Null) {
         bsonReader.ReadNull();
         return null;
     } else {
         return BsonSymbol.Create(bsonReader.ReadSymbol());
     }
 }