WriteDouble() публичный абстрактный Метод

Writes a BSON Double to the writer.
public abstract WriteDouble ( double value ) : void
value double The Double value.
Результат void
        public override void Serialize(BsonWriter bsonWriter, System.Type nominalType, object value, IBsonSerializationOptions options)
        {
            var rectangle = (Rectangle) value;

            bsonWriter.WriteStartDocument();
            WriteVector(bsonWriter,"Min",rectangle.Min);
            WriteVector(bsonWriter,"Max",rectangle.Max);
            
            bsonWriter.WriteDouble("Width",rectangle.Width);
            bsonWriter.WriteDouble("Height",rectangle.Height);
            bsonWriter.WriteEndDocument();
        }
        /// <summary>
        /// Serializes an object to a BsonWriter.
        /// </summary>
        /// <param name="bsonWriter">The BsonWriter.</param>
        /// <param name="nominalType">The nominal type.</param>
        /// <param name="value">The object.</param>
        /// <param name="options">The serialization options.</param>
        public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
        {
            if (value == null)
            {
                bsonWriter.WriteNull();
            }
            else
            {
                var coordinates = (GeoJson2DCoordinates)value;

                bsonWriter.WriteStartArray();
                bsonWriter.WriteDouble(coordinates.X);
                bsonWriter.WriteDouble(coordinates.Y);
                bsonWriter.WriteEndArray();
            }
        }
        /// <summary>
        /// Serializes an object to a BsonWriter.
        /// </summary>
        /// <param name="bsonWriter">The BsonWriter.</param>
        /// <param name="nominalType">The nominal type.</param>
        /// <param name="value">The object.</param>
        /// <param name="options">The serialization options.</param>
        public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
        {
            if (value == null)
            {
                bsonWriter.WriteNull();
            }
            else
            {
                var coordinates = (GeoJson3DProjectedCoordinates)value;

                bsonWriter.WriteStartArray();
                bsonWriter.WriteDouble(coordinates.Easting);
                bsonWriter.WriteDouble(coordinates.Northing);
                bsonWriter.WriteDouble(coordinates.Altitude);
                bsonWriter.WriteEndArray();
            }
        }
Пример #4
0
        protected void WriteNullableDouble(BsonWriter writer,string name,double? value)
        {
            writer.WriteName(name);

            if ( value != null )
            {
                writer.WriteDouble(value.Value);
            }
            else
            {
                writer.WriteNull();
            }
        }
Пример #5
0
        public void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
        {
            var underlyingValue = value.GetType().GetProperty("Value").GetValue(value, null);
            var underlyingValueType = nominalType.GetConceptValueType();
			if (underlyingValueType == typeof(Guid)) {
				var guid = (Guid)underlyingValue;
				var guidAsBytes = guid.ToByteArray ();
				bsonWriter.WriteBinaryData (guidAsBytes, BsonBinarySubType.UuidLegacy, GuidRepresentation.CSharpLegacy);
			} else if (underlyingValueType == typeof(double))
				bsonWriter.WriteDouble ((double)underlyingValue);
			else if (underlyingValueType == typeof(float))
				bsonWriter.WriteDouble ((double)underlyingValue);
			else if (underlyingValueType == typeof(Int32))
				bsonWriter.WriteInt32 ((Int32)underlyingValue);
			else if (underlyingValueType == typeof(Int64))
				bsonWriter.WriteInt64 ((Int64)underlyingValue);
			else if (underlyingValueType == typeof(bool))
				bsonWriter.WriteBoolean ((bool)underlyingValue);
			else if (underlyingValueType == typeof(string))
				bsonWriter.WriteString ((string)(underlyingValue ?? string.Empty));
			else if (underlyingValueType == typeof(decimal))
				bsonWriter.WriteString (underlyingValue.ToString());
        }
 void IBsonSerializable.Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     IBsonSerializationOptions options
 )
 {
     bsonWriter.WriteStartDocument();
     bsonWriter.WriteDateTime("ts", BsonUtils.ToMillisecondsSinceEpoch(timestamp));
     if (info != null) {
         bsonWriter.WriteString("info", info);
     }
     if (op != null) {
         bsonWriter.WriteString("op", op);
     }
     if (@namespace != null) {
         bsonWriter.WriteString("ns", @namespace);
     }
     if (command != null) {
         bsonWriter.WriteName("command");
         command.WriteTo(bsonWriter);
     }
     if (query != null) {
         bsonWriter.WriteName("query");
         query.WriteTo(bsonWriter);
     }
     if (updateObject != null) {
         bsonWriter.WriteName("updateobj");
         updateObject.WriteTo(bsonWriter);
     }
     if (cursorId != 0) {
         bsonWriter.WriteInt64("cursorid", cursorId);
     }
     if (numberToReturn != 0) {
         bsonWriter.WriteInt32("ntoreturn", numberToReturn);
     }
     if (numberToSkip != 0) {
         bsonWriter.WriteInt32("ntoskip", numberToSkip);
     }
     if (exhaust) {
         bsonWriter.WriteBoolean("exhaust", exhaust);
     }
     if (numberScanned != 0) {
         bsonWriter.WriteInt32("nscanned", numberScanned);
     }
     if (idHack) {
         bsonWriter.WriteBoolean("idhack", idHack);
     }
     if (scanAndOrder) {
         bsonWriter.WriteBoolean("scanAndOrder", scanAndOrder);
     }
     if (moved) {
         bsonWriter.WriteBoolean("moved", moved);
     }
     if (fastMod) {
         bsonWriter.WriteBoolean("fastmod", fastMod);
     }
     if (fastModInsert) {
         bsonWriter.WriteBoolean("fastmodinsert", fastModInsert);
     }
     if (upsert) {
         bsonWriter.WriteBoolean("upsert", upsert);
     }
     if (keyUpdates != 0) {
         bsonWriter.WriteInt32("keyUpdates", keyUpdates);
     }
     if (exception != null) {
         bsonWriter.WriteString("exception", exception);
     }
     if (exceptionCode != 0) {
         bsonWriter.WriteInt32("exceptionCode", exceptionCode);
     }
     if (numberReturned != 0) {
         bsonWriter.WriteInt32("nreturned", numberReturned);
     }
     if (responseLength != 0) {
         bsonWriter.WriteInt32("responseLength", responseLength);
     }
     bsonWriter.WriteDouble("millis", duration.TotalMilliseconds);
     if (client != null) {
         bsonWriter.WriteString("client", client);
     }
     if (user != null) {
         bsonWriter.WriteString("user", user);
     }
     if (error != null) {
         bsonWriter.WriteString("err", error);
     }
     if (abbreviated != null) {
         bsonWriter.WriteString("abbreviated", abbreviated);
     }
     bsonWriter.WriteEndDocument();
 }
 public override void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     IBsonSerializationOptions options
 ) {
     var uint16Value = (ushort) value;
     var representation = (options == null) ? BsonType.Int32 : ((RepresentationSerializationOptions) options).Representation;
     switch (representation) {
         case BsonType.Double:
             bsonWriter.WriteDouble(uint16Value);
             break;
         case BsonType.Int32:
             bsonWriter.WriteInt32(uint16Value);
             break;
         case BsonType.Int64:
             bsonWriter.WriteInt64(uint16Value);
             break;
         case BsonType.String:
             bsonWriter.WriteString(XmlConvert.ToString(uint16Value));
             break;
         default:
             var message = string.Format("'{0}' is not a valid representation for type 'UInt16'", representation);
             throw new BsonSerializationException(message);
     }
 }
 public void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
 {
     var version = (EventSourceVersion)value;
     var versionAsDouble = version.Combine();
     bsonWriter.WriteDouble(versionAsDouble);
 }
        /// <summary>
        /// Serializes an object to a BsonWriter.
        /// </summary>
        /// <param name="bsonWriter">The BsonWriter.</param>
        /// <param name="nominalType">The nominal type.</param>
        /// <param name="value">The object.</param>
        /// <param name="options">The serialization options.</param>
        public override void Serialize(
            BsonWriter bsonWriter,
            Type nominalType,
            object value,
            IBsonSerializationOptions options)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var bsonDouble = (BsonDouble)value;
            bsonWriter.WriteDouble(bsonDouble.Value);
        }
 /// <summary>
 /// Serializes an object to a BsonWriter.
 /// </summary>
 /// <param name="bsonWriter">The BsonWriter.</param>
 /// <param name="nominalType">The nominal type.</param>
 /// <param name="value">The object.</param>
 /// <param name="options">The serialization options.</param>
 public override void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     IBsonSerializationOptions options
 ) {
     var doubleValue = (double) value;
     var representationOptions = (RepresentationSerializationOptions) options ?? defaultRepresentationOptions;
     switch (representationOptions.Representation) {
         case BsonType.Double:
             bsonWriter.WriteDouble(doubleValue);
             break;
         case BsonType.Int32:
             bsonWriter.WriteInt32(representationOptions.ToInt32(doubleValue));
             break;
         case BsonType.Int64:
             bsonWriter.WriteInt64(representationOptions.ToInt64(doubleValue));
             break;
         case BsonType.String:
             bsonWriter.WriteString(XmlConvert.ToString(doubleValue));
             break;
         default:
             var message = string.Format("'{0}' is not a valid representation for type 'Double'", representationOptions.Representation);
             throw new BsonSerializationException(message);
     }
 }
Пример #11
0
        /// <summary>
        /// Serializes an object to a BsonWriter.
        /// </summary>
        /// <param name="bsonWriter">The BsonWriter.</param>
        /// <param name="nominalType">The nominal type.</param>
        /// <param name="value">The object.</param>
        /// <param name="options">The serialization options.</param>
        public override void Serialize(
            BsonWriter bsonWriter,
            Type nominalType,
            object value,
            IBsonSerializationOptions options)
        {
            var timeSpan = (TimeSpan)value;

            // support RepresentationSerializationOptions for backward compatibility
            var representationSerializationOptions = options as RepresentationSerializationOptions;
            if (representationSerializationOptions != null)
            {
                options = new TimeSpanSerializationOptions(representationSerializationOptions.Representation);
            }
            var timeSpanSerializationOptions = EnsureSerializationOptions<TimeSpanSerializationOptions>(options);

            if (timeSpanSerializationOptions.Representation == BsonType.String)
            {
                bsonWriter.WriteString(timeSpan.ToString()); // for TimeSpan use .NET's format instead of XmlConvert.ToString
            }
            else if (timeSpanSerializationOptions.Units == TimeSpanUnits.Ticks)
            {
                var ticks = timeSpan.Ticks;
                switch (timeSpanSerializationOptions.Representation)
                {
                    case BsonType.Double: bsonWriter.WriteDouble((double)ticks); break;
                    case BsonType.Int32: bsonWriter.WriteInt32((int)ticks); break;
                    case BsonType.Int64: bsonWriter.WriteInt64(ticks); break;
                    default:
                        var message = string.Format("'{0}' is not a valid TimeSpan representation.", timeSpanSerializationOptions.Representation);
                        throw new BsonSerializationException(message);
                }
            }
            else
            {
                double interval;
                switch (timeSpanSerializationOptions.Units)
                {
                    case TimeSpanUnits.Days: interval = timeSpan.TotalDays; break;
                    case TimeSpanUnits.Hours: interval = timeSpan.TotalHours; break;
                    case TimeSpanUnits.Minutes: interval = timeSpan.TotalMinutes; break;
                    case TimeSpanUnits.Seconds: interval = timeSpan.TotalSeconds; break;
                    case TimeSpanUnits.Milliseconds: interval = timeSpan.TotalMilliseconds; break;
                    case TimeSpanUnits.Nanoseconds: interval = timeSpan.TotalMilliseconds * 1000.0; break;
                    default:
                        var message = string.Format("'{0}' is not a valid TimeSpanUnits value.", timeSpanSerializationOptions.Units);
                        throw new BsonSerializationException(message);
                }

                switch (timeSpanSerializationOptions.Representation)
                {
                    case BsonType.Double: bsonWriter.WriteDouble(interval); break;
                    case BsonType.Int32: bsonWriter.WriteInt32((int)interval); break;
                    case BsonType.Int64: bsonWriter.WriteInt64((long)interval); break;
                    default:
                        var message = string.Format("'{0}' is not a valid TimeSpan representation.", timeSpanSerializationOptions.Representation);
                        throw new BsonSerializationException(message);
                }
            }
        }
        /// <summary>
        /// Serializes an object to a BsonWriter.
        /// </summary>
        /// <param name="bsonWriter">The BsonWriter.</param>
        /// <param name="nominalType">The nominal type.</param>
        /// <param name="value">The object.</param>
        /// <param name="options">The serialization options.</param>
        public override void Serialize(
            BsonWriter bsonWriter,
            Type nominalType,
            object value,
            IBsonSerializationOptions options)
        {
            var int16Value = (short)value;
            var representationSerializationOptions = EnsureSerializationOptions<RepresentationSerializationOptions>(options);

            switch (representationSerializationOptions.Representation)
            {
                case BsonType.Double:
                    bsonWriter.WriteDouble(representationSerializationOptions.ToDouble(int16Value));
                    break;
                case BsonType.Int32:
                    bsonWriter.WriteInt32(representationSerializationOptions.ToInt32(int16Value));
                    break;
                case BsonType.Int64:
                    bsonWriter.WriteInt64(representationSerializationOptions.ToInt64(int16Value));
                    break;
                case BsonType.String:
                    bsonWriter.WriteString(XmlConvert.ToString(int16Value));
                    break;
                default:
                    var message = string.Format("'{0}' is not a valid Int16 representation.", representationSerializationOptions.Representation);
                    throw new BsonSerializationException(message);
            }
        }
        /// <summary>
        /// Serializes an object to a BsonWriter.
        /// </summary>
        /// <param name="bsonWriter">The BsonWriter.</param>
        /// <param name="nominalType">The nominal type.</param>
        /// <param name="value">The object.</param>
        /// <param name="options">The serialization options.</param>
        public override void Serialize(
            BsonWriter bsonWriter,
            Type nominalType,
            object value,
            IBsonSerializationOptions options)
        {
            var timeSpan = (TimeSpan)value;

            // support RepresentationSerializationOptions for backward compatibility
            var representationSerializationOptions = options as RepresentationSerializationOptions;
            if (representationSerializationOptions != null)
            {
                options = new TimeSpanSerializationOptions(representationSerializationOptions.Representation);
            }
            var timeSpanSerializationOptions = EnsureSerializationOptions<TimeSpanSerializationOptions>(options);

            switch (timeSpanSerializationOptions.Representation)
            {
                case BsonType.Double:
                    bsonWriter.WriteDouble(ToDouble(timeSpan, timeSpanSerializationOptions.Units));
                    break;
                case BsonType.Int32:
                    bsonWriter.WriteInt32(ToInt32(timeSpan, timeSpanSerializationOptions.Units));
                    break;
                case BsonType.Int64:
                    bsonWriter.WriteInt64(ToInt64(timeSpan, timeSpanSerializationOptions.Units));
                    break;
                case BsonType.String:
                    bsonWriter.WriteString(timeSpan.ToString()); // not XmlConvert.ToString (we're using .NET's format for TimeSpan)
                    break;
                default:
                    var message = string.Format("'{0}' is not a valid TimeSpan representation.", timeSpanSerializationOptions.Representation);
                    throw new BsonSerializationException(message);
            }
        }
 void IBsonSerializable.Serialize(BsonWriter bsonWriter, Type nominalType, IBsonSerializationOptions options)
 {
     bsonWriter.WriteStartDocument();
     bsonWriter.WriteDateTime("ts", BsonUtils.ToMillisecondsSinceEpoch(_timestamp));
     if (_info != null)
     {
         bsonWriter.WriteString("info", _info);
     }
     if (_op != null)
     {
         bsonWriter.WriteString("op", _op);
     }
     if (_namespace != null)
     {
         bsonWriter.WriteString("ns", _namespace);
     }
     if (_command != null)
     {
         bsonWriter.WriteName("command");
         _command.WriteTo(bsonWriter);
     }
     if (_query != null)
     {
         bsonWriter.WriteName("query");
         _query.WriteTo(bsonWriter);
     }
     if (_updateObject != null)
     {
         bsonWriter.WriteName("updateobj");
         _updateObject.WriteTo(bsonWriter);
     }
     if (_cursorId != 0)
     {
         bsonWriter.WriteInt64("cursorid", _cursorId);
     }
     if (_numberToReturn != 0)
     {
         bsonWriter.WriteInt32("ntoreturn", _numberToReturn);
     }
     if (_numberToSkip != 0)
     {
         bsonWriter.WriteInt32("ntoskip", _numberToSkip);
     }
     if (_exhaust)
     {
         bsonWriter.WriteBoolean("exhaust", _exhaust);
     }
     if (_numberScanned != 0)
     {
         bsonWriter.WriteInt32("nscanned", _numberScanned);
     }
     if (_idHack)
     {
         bsonWriter.WriteBoolean("idhack", _idHack);
     }
     if (_scanAndOrder)
     {
         bsonWriter.WriteBoolean("scanAndOrder", _scanAndOrder);
     }
     if (_moved)
     {
         bsonWriter.WriteBoolean("moved", _moved);
     }
     if (_fastMod)
     {
         bsonWriter.WriteBoolean("fastmod", _fastMod);
     }
     if (_fastModInsert)
     {
         bsonWriter.WriteBoolean("fastmodinsert", _fastModInsert);
     }
     if (_upsert)
     {
         bsonWriter.WriteBoolean("upsert", _upsert);
     }
     if (_keyUpdates != 0)
     {
         bsonWriter.WriteInt32("keyUpdates", _keyUpdates);
     }
     if (_exception != null)
     {
         bsonWriter.WriteString("exception", _exception);
     }
     if (_exceptionCode != 0)
     {
         bsonWriter.WriteInt32("exceptionCode", _exceptionCode);
     }
     if (_numberReturned != 0)
     {
         bsonWriter.WriteInt32("nreturned", _numberReturned);
     }
     if (_responseLength != 0)
     {
         bsonWriter.WriteInt32("responseLength", _responseLength);
     }
     bsonWriter.WriteDouble("millis", _duration.TotalMilliseconds);
     if (_client != null)
     {
         bsonWriter.WriteString("client", _client);
     }
     if (_user != null)
     {
         bsonWriter.WriteString("user", _user);
     }
     if (_error != null)
     {
         bsonWriter.WriteString("err", _error);
     }
     if (_abbreviated != null)
     {
         bsonWriter.WriteString("abbreviated", _abbreviated);
     }
     bsonWriter.WriteEndDocument();
 }
Пример #15
0
        /// <summary>
        /// Serializes an object to a BsonWriter.
        /// </summary>
        /// <param name="bsonWriter">The BsonWriter.</param>
        /// <param name="nominalType">The nominal type.</param>
        /// <param name="value">The object.</param>
        /// <param name="options">The serialization options.</param>
        public override void Serialize(
            BsonWriter bsonWriter,
            Type nominalType,
            object value,
            IBsonSerializationOptions options)
        {
            if (value == null)
            {
                bsonWriter.WriteNull();
            }
            else
            {
                var profileInfo = (SystemProfileInfo)value;

                bsonWriter.WriteStartDocument();
                bsonWriter.WriteDateTime("ts", BsonUtils.ToMillisecondsSinceEpoch(profileInfo.Timestamp));
                if (profileInfo.Info != null)
                {
                    bsonWriter.WriteString("info", profileInfo.Info);
                }
                if (profileInfo.Op != null)
                {
                    bsonWriter.WriteString("op", profileInfo.Op);
                }
                if (profileInfo.Namespace != null)
                {
                    bsonWriter.WriteString("ns", profileInfo.Namespace);
                }
                if (profileInfo.Command != null)
                {
                    bsonWriter.WriteName("command");
                    profileInfo.Command.WriteTo(bsonWriter);
                }
                if (profileInfo.Query != null)
                {
                    bsonWriter.WriteName("query");
                    profileInfo.Query.WriteTo(bsonWriter);
                }
                if (profileInfo.UpdateObject != null)
                {
                    bsonWriter.WriteName("updateobj");
                    profileInfo.UpdateObject.WriteTo(bsonWriter);
                }
                if (profileInfo.CursorId != 0)
                {
                    bsonWriter.WriteInt64("cursorid", profileInfo.CursorId);
                }
                if (profileInfo.NumberToReturn != 0)
                {
                    bsonWriter.WriteInt32("ntoreturn", profileInfo.NumberToReturn);
                }
                if (profileInfo.NumberToSkip != 0)
                {
                    bsonWriter.WriteInt32("ntoskip", profileInfo.NumberToSkip);
                }
                if (profileInfo.Exhaust)
                {
                    bsonWriter.WriteBoolean("exhaust", profileInfo.Exhaust);
                }
                if (profileInfo.NumberScanned != 0)
                {
                    bsonWriter.WriteInt32("nscanned", profileInfo.NumberScanned);
                }
                if (profileInfo.IdHack)
                {
                    bsonWriter.WriteBoolean("idhack", profileInfo.IdHack);
                }
                if (profileInfo.ScanAndOrder)
                {
                    bsonWriter.WriteBoolean("scanAndOrder", profileInfo.ScanAndOrder);
                }
                if (profileInfo.Moved)
                {
                    bsonWriter.WriteBoolean("moved", profileInfo.Moved);
                }
                if (profileInfo.FastMod)
                {
                    bsonWriter.WriteBoolean("fastmod", profileInfo.FastMod);
                }
                if (profileInfo.FastModInsert)
                {
                    bsonWriter.WriteBoolean("fastmodinsert", profileInfo.FastModInsert);
                }
                if (profileInfo.Upsert)
                {
                    bsonWriter.WriteBoolean("upsert", profileInfo.Upsert);
                }
                if (profileInfo.KeyUpdates != 0)
                {
                    bsonWriter.WriteInt32("keyUpdates", profileInfo.KeyUpdates);
                }
                if (profileInfo.Exception != null)
                {
                    bsonWriter.WriteString("exception", profileInfo.Exception);
                }
                if (profileInfo.ExceptionCode != 0)
                {
                    bsonWriter.WriteInt32("exceptionCode", profileInfo.ExceptionCode);
                }
                if (profileInfo.NumberReturned != 0)
                {
                    bsonWriter.WriteInt32("nreturned", profileInfo.NumberReturned);
                }
                if (profileInfo.ResponseLength != 0)
                {
                    bsonWriter.WriteInt32("responseLength", profileInfo.ResponseLength);
                }
                bsonWriter.WriteDouble("millis", profileInfo.Duration.TotalMilliseconds);
                if (profileInfo.Client != null)
                {
                    bsonWriter.WriteString("client", profileInfo.Client);
                }
                if (profileInfo.User != null)
                {
                    bsonWriter.WriteString("user", profileInfo.User);
                }
                if (profileInfo.Error != null)
                {
                    bsonWriter.WriteString("err", profileInfo.Error);
                }
                if (profileInfo.Abbreviated != null)
                {
                    bsonWriter.WriteString("abbreviated", profileInfo.Abbreviated);
                }
                bsonWriter.WriteEndDocument();
            }
        }
 public override void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     bool serializeIdFirst
 ) {
     var floatValue = (float) value;
     var doubleValue = (floatValue == float.MinValue) ? double.MinValue : (floatValue == float.MaxValue) ? double.MaxValue : floatValue;
     bsonWriter.WriteDouble(doubleValue);
 }
 /// <summary>
 /// Serializes an object to a BsonWriter.
 /// </summary>
 /// <param name="bsonWriter">The BsonWriter.</param>
 /// <param name="nominalType">The nominal type.</param>
 /// <param name="value">The object.</param>
 /// <param name="options">The serialization options.</param>
 public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
 {
     var floatValue = (float)value;
     var representationOptions = (RepresentationSerializationOptions)options ?? defaultRepresentationOptions;
     switch (representationOptions.Representation)
     {
         case BsonType.Double:
             bsonWriter.WriteDouble(representationOptions.ToDouble(floatValue));
             break;
         case BsonType.Int32:
             bsonWriter.WriteInt32(representationOptions.ToInt32(floatValue));
             break;
         case BsonType.Int64:
             bsonWriter.WriteInt64(representationOptions.ToInt64(floatValue));
             break;
         case BsonType.String:
             bsonWriter.WriteString(floatValue.ToString("R", NumberFormatInfo.InvariantInfo));
             break;
         default:
             var message = string.Format("'{0}' is not a valid representation for type Single.", representationOptions.Representation);
             throw new BsonSerializationException(message);
     }
 }
 public override void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     bool serializeIdFirst
 )
 {
     if (value == null) {
         bsonWriter.WriteNull();
     } else {
         bsonWriter.WriteDouble(((BsonDouble) value).Value);
     }
 }
        /// <summary>
        /// Serializes an object to a BsonWriter.
        /// </summary>
        /// <param name="bsonWriter">The BsonWriter.</param>
        /// <param name="nominalType">The nominal type.</param>
        /// <param name="value">The object.</param>
        /// <param name="options">The serialization options.</param>
        public override void Serialize(
            BsonWriter bsonWriter,
            Type nominalType,
            object value,
            IBsonSerializationOptions options)
        {
            var boolValue = (bool)value;
            var representationSerializationOptions = EnsureSerializationOptions<RepresentationSerializationOptions>(options);

            switch (representationSerializationOptions.Representation)
            {
                case BsonType.Boolean:
                    bsonWriter.WriteBoolean(boolValue);
                    break;
                case BsonType.Double:
                    bsonWriter.WriteDouble(boolValue ? 1.0 : 0.0);
                    break;
                case BsonType.Int32:
                    bsonWriter.WriteInt32(boolValue ? 1 : 0);
                    break;
                case BsonType.Int64:
                    bsonWriter.WriteInt64(boolValue ? 1 : 0);
                    break;
                case BsonType.String:
                    bsonWriter.WriteString(XmlConvert.ToString(boolValue));
                    break;
                default:
                    var message = string.Format("'{0}' is not a valid Boolean representation.", representationSerializationOptions.Representation);
                    throw new BsonSerializationException(message);
            }
        }
 public override void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     IBsonSerializationOptions options
 ) {
     var floatValue = (float) value;
     var doubleValue = (floatValue == float.MinValue) ? double.MinValue : (floatValue == float.MaxValue) ? double.MaxValue : floatValue;
     var representation = (options == null) ? BsonType.Double : ((RepresentationSerializationOptions) options).Representation;
     switch (representation) {
         case BsonType.Double:
             bsonWriter.WriteDouble(doubleValue);
             break;
         case BsonType.Int32:
             bsonWriter.WriteInt32((int) doubleValue);
             break;
         case BsonType.Int64:
             bsonWriter.WriteInt64((long) doubleValue);
             break;
         case BsonType.String:
             bsonWriter.WriteString(XmlConvert.ToString(doubleValue));
             break;
         default:
             var message = string.Format("'{0}' is not a valid representation for type 'Single'", representation);
             throw new BsonSerializationException(message);
     }
 }
        /// <summary>
        /// Serializes an object to a BsonWriter.
        /// </summary>
        /// <param name="bsonWriter">The BsonWriter.</param>
        /// <param name="nominalType">The nominal type.</param>
        /// <param name="value">The object.</param>
        /// <param name="options">The serialization options.</param>
        public override void Serialize(
            BsonWriter bsonWriter,
            Type nominalType,
            object value,
            IBsonSerializationOptions options)
        {
            var decimalValue = (Decimal)value;
            var representationSerializationOptions = EnsureSerializationOptions<RepresentationSerializationOptions>(options);

            switch (representationSerializationOptions.Representation)
            {
                case BsonType.Array:
                    bsonWriter.WriteStartArray();
                    var bits = Decimal.GetBits(decimalValue);
                    bsonWriter.WriteInt32(bits[0]);
                    bsonWriter.WriteInt32(bits[1]);
                    bsonWriter.WriteInt32(bits[2]);
                    bsonWriter.WriteInt32(bits[3]);
                    bsonWriter.WriteEndArray();
                    break;
                case BsonType.Double:
                    bsonWriter.WriteDouble(representationSerializationOptions.ToDouble(decimalValue));
                    break;
                case BsonType.Int32:
                    bsonWriter.WriteInt32(representationSerializationOptions.ToInt32(decimalValue));
                    break;
                case BsonType.Int64:
                    bsonWriter.WriteInt64(representationSerializationOptions.ToInt64(decimalValue));
                    break;
                case BsonType.String:
                    bsonWriter.WriteString(XmlConvert.ToString(decimalValue));
                    break;
                default:
                    var message = string.Format("'{0}' is not a valid Decimal representation.", representationSerializationOptions.Representation);
                    throw new BsonSerializationException(message);
            }
        }
 public override void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     bool serializeIdFirst
 )
 {
     bsonWriter.WriteDouble((double) value);
 }
        /// <summary>
        /// Serializes an object to a BsonWriter.
        /// </summary>
        /// <param name="bsonWriter">The BsonWriter.</param>
        /// <param name="nominalType">The nominal type.</param>
        /// <param name="value">The object.</param>
        /// <param name="options">The serialization options.</param>
        public override void Serialize(
            BsonWriter bsonWriter,
            Type nominalType,
            object value,
            IBsonSerializationOptions options)
        {
            var doubleValue = (double)value;
            var representationSerializationOptions = EnsureSerializationOptions<RepresentationSerializationOptions>(options);

            switch (representationSerializationOptions.Representation)
            {
                case BsonType.Double:
                    bsonWriter.WriteDouble(doubleValue);
                    break;
                case BsonType.Int32:
                    bsonWriter.WriteInt32(representationSerializationOptions.ToInt32(doubleValue));
                    break;
                case BsonType.Int64:
                    bsonWriter.WriteInt64(representationSerializationOptions.ToInt64(doubleValue));
                    break;
                case BsonType.String:
                    bsonWriter.WriteString(doubleValue.ToString("R", NumberFormatInfo.InvariantInfo));
                    break;
                default:
                    var message = string.Format("'{0}' is not a valid Double representation.", representationSerializationOptions.Representation);
                    throw new BsonSerializationException(message);
            }
        }
 public override void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     bool serializeIdFirst
 )
 {
     var boolValue = (bool) value;
     switch (representation) {
         case BsonType.Boolean:
             bsonWriter.WriteBoolean(boolValue);
             break;
         case BsonType.Double:
             bsonWriter.WriteDouble(boolValue ? 1.0 : 0.0);
             break;
         case BsonType.Int32:
             bsonWriter.WriteInt32(boolValue ? 1 : 0);
             break;
         case BsonType.Int64:
             bsonWriter.WriteInt64(boolValue ? 1 : 0);
             break;
         case BsonType.String:
             bsonWriter.WriteString(XmlConvert.ToString(boolValue));
             break;
         default:
             var message = string.Format("'{0}' is not a valid representation for type 'Boolean'", representation);
             throw new BsonSerializationException(message);
     }
 }