本文整理汇总了C#中MongoDB.Bson.IO.BsonWriter.WriteDouble方法的典型用法代码示例。如果您正苦于以下问题:C# BsonWriter.WriteDouble方法的具体用法?C# BsonWriter.WriteDouble怎么用?C# BsonWriter.WriteDouble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Bson.IO.BsonWriter
的用法示例。
在下文中一共展示了BsonWriter.WriteDouble方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serialize
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();
}
示例2: Serialize
/// <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();
}
}
示例3: Serialize
/// <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: WriteNullableDouble
protected void WriteNullableDouble(BsonWriter writer,string name,double? value)
{
writer.WriteName(name);
if ( value != null )
{
writer.WriteDouble(value.Value);
}
else
{
writer.WriteNull();
}
}
示例5: Serialize
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());
}
示例6:
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();
}
示例7: Serialize
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);
}
}
示例8: Serialize
public void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
var version = (EventSourceVersion)value;
var versionAsDouble = version.Combine();
bsonWriter.WriteDouble(versionAsDouble);
}
示例9: Serialize
/// <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);
}
示例10: Serialize
/// <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: Serialize
/// <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);
}
}
}
示例12: Serialize
/// <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);
}
}
示例13: Serialize
/// <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);
}
}
示例14:
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);
}
//.........这里部分代码省略.........
示例15: Serialize
//.........这里部分代码省略.........
}
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();
}
}