当前位置: 首页>>代码示例>>C#>>正文


C# BsonWriter.WriteInt64方法代码示例

本文整理汇总了C#中MongoDB.Bson.IO.BsonWriter.WriteInt64方法的典型用法代码示例。如果您正苦于以下问题:C# BsonWriter.WriteInt64方法的具体用法?C# BsonWriter.WriteInt64怎么用?C# BsonWriter.WriteInt64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoDB.Bson.IO.BsonWriter的用法示例。


在下文中一共展示了BsonWriter.WriteInt64方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Serialize

        public override void Serialize(
            BsonWriter bsonWriter,
            Type nominalType,
            object value,
            IBsonSerializationOptions options) {
            var dateTimeOffset = (DateTimeOffset)value;
            var representationSerializationOptions = EnsureSerializationOptions<RepresentationSerializationOptions>(options);

            switch (representationSerializationOptions.Representation) {
            case BsonType.Array:
                bsonWriter.WriteStartArray();
                bsonWriter.WriteInt64(dateTimeOffset.UtcTicks);
                bsonWriter.WriteInt32((int)dateTimeOffset.Offset.TotalMinutes);
                bsonWriter.WriteEndArray();
                break;
            case BsonType.Document:
                bsonWriter.WriteStartDocument();
                bsonWriter.WriteDateTime("DateTime", BsonUtils.ToMillisecondsSinceEpoch(dateTimeOffset.UtcDateTime));
                bsonWriter.WriteInt64("Ticks", dateTimeOffset.UtcTicks);
                bsonWriter.WriteInt32("Offset", (int)dateTimeOffset.Offset.TotalMinutes);
                bsonWriter.WriteEndDocument();
                break;
            default:
                var message = string.Format("'{0}' is not a valid DateTimeOffset representation.", representationSerializationOptions.Representation);
                throw new BsonSerializationException(message);
            }
        }
开发者ID:aamarber,项目名称:Exceptionless,代码行数:27,代码来源:UtcDateTimeOffsetSerializer.cs

示例2: Serialize

        public override void Serialize(
            BsonWriter bsonWriter,
            Type nominalType,
            object value,
            IBsonSerializationOptions options)
        {
            var versionValue = (Version) value;
            var representationSerializationOptions =
                EnsureSerializationOptions<RepresentationSerializationOptions>(options);

            switch (representationSerializationOptions.Representation)
            {
                case BsonType.Int64:
                    bsonWriter.WriteInt64(SerializeVersion(versionValue));
                    break;
                default:
                    throw new BsonSerializationException(string.Format("'{0}' is not a valid Version representation.", representationSerializationOptions.Representation));
            }
        }
开发者ID:RasmusTG,项目名称:mongo-csharp-migrations,代码行数:19,代码来源:LightweightVersionSerializer.cs

示例3: 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());
        }
开发者ID:LenFon,项目名称:Bifrost,代码行数:23,代码来源:ConceptSerializer.cs

示例4: 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 dateTime = (DateTime) value;
            var dateTimeOptions = (options == null) ? DateTimeSerializationOptions.Defaults : (DateTimeSerializationOptions) options;

            if (dateTimeOptions.DateOnly) {
                if (dateTime.TimeOfDay != TimeSpan.Zero) {
                    throw new BsonSerializationException("TimeOfDay component for DateOnly DateTime value is not zero");
                }
            }

            if (dateTimeOptions.Representation != BsonType.String) {
                if (dateTime.Kind != DateTimeKind.Utc) {
                    if (dateTimeOptions.DateOnly) {
                        dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc); // not ToUniversalTime!
                    } else {
                        dateTime = ToUniversalTimeHelper(dateTime);
                    }
                }
            }

            switch (dateTimeOptions.Representation) {
                case BsonType.DateTime:
                    bsonWriter.WriteDateTime(dateTime);
                    break;
                case BsonType.Document:
                    bsonWriter.WriteStartDocument();
                    bsonWriter.WriteDateTime("DateTime", dateTime);
                    bsonWriter.WriteInt64("Ticks", dateTime.Ticks);
                    bsonWriter.WriteEndDocument();
                    break;
                case BsonType.Int64:
                    bsonWriter.WriteInt64(dateTime.Ticks);
                    break;
                case BsonType.String:
                    if (dateTimeOptions.DateOnly) {
                        bsonWriter.WriteString(dateTime.ToString("yyyy-MM-dd"));
                    } else {
                        // we're not using XmlConvert.ToString because of bugs in Mono
                        if (dateTime == DateTime.MinValue || dateTime == DateTime.MaxValue) {
                            // serialize MinValue and MaxValue as Unspecified so we do NOT get the time zone offset
                            dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Unspecified);
                        } else if (dateTime.Kind == DateTimeKind.Unspecified) {
                            // serialize Unspecified as Local se we get the time zone offset
                            dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Local);
                        }
                        bsonWriter.WriteString(dateTime.ToString("yyyy-MM-ddTHH:mm:ss.FFFFFFFK"));
                    }
                    break;
                default:
                    var message = string.Format("'{0}' is not a valid representation for type 'DateTime'", dateTimeOptions.Representation);
                    throw new BsonSerializationException(message);
            }
        }
开发者ID:ebix,项目名称:mongo-csharp-driver,代码行数:65,代码来源:BsonPrimitiveSerializers.cs

示例5: 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);
            }
        }
开发者ID:robinNode,项目名称:mongo-csharp-driver,代码行数:42,代码来源:TimeSpanSerializer.cs

示例6: 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);
            }
        }
开发者ID:CloudMetal,项目名称:mongo-csharp-driver,代码行数:35,代码来源:Int16Serializer.cs

示例7: 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 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);
            }
        }
开发者ID:ncipollina,项目名称:mongo-csharp-driver,代码行数:38,代码来源:BsonPrimitiveSerializers.cs

示例8: 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 byteValue = (byte)value;
            var representationSerializationOptions = EnsureSerializationOptions<RepresentationSerializationOptions>(options);

            switch (representationSerializationOptions.Representation)
            {
                case BsonType.Binary:
                    bsonWriter.WriteBytes(new byte[] { byteValue });
                    break;
                case BsonType.Int32:
                    bsonWriter.WriteInt32(byteValue);
                    break;
                case BsonType.Int64:
                    bsonWriter.WriteInt64(byteValue);
                    break;
                case BsonType.String:
                    bsonWriter.WriteString(string.Format("{0:x2}", byteValue));
                    break;
                default:
                    var message = string.Format("'{0}' is not a valid Byte representation.", representationSerializationOptions.Representation);
                    throw new BsonSerializationException(message);
            }
        }
开发者ID:robinNode,项目名称:mongo-csharp-driver,代码行数:35,代码来源:ByteSerializer.cs

示例9: Serialize

 public override void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     bool serializeIdFirst
 )
 {
     bsonWriter.WriteInt64((long) value);
 }
开发者ID:tomthink,项目名称:mongo-csharp-driver,代码行数:9,代码来源:BsonPrimitiveSerializers.cs

示例10: Serialize

 public override void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     bool serializeIdFirst
 ) {
     // note: the DateTime portion cannot be serialized as a BsonType.DateTime because it is NOT in UTC
     var dateTimeOffset = (DateTimeOffset) value;
     switch (representation) {
         case BsonType.Array:
             bsonWriter.WriteStartArray();
             bsonWriter.WriteInt64("0", dateTimeOffset.DateTime.Ticks);
             bsonWriter.WriteInt32("1", (int) dateTimeOffset.Offset.TotalMinutes);
             bsonWriter.WriteEndArray();
             break;
         case BsonType.String:
             bsonWriter.WriteString(XmlConvert.ToString(dateTimeOffset));
             break;
         default:
             throw new BsonInternalException("Unexpected representation");
     }
 }
开发者ID:kenegozi,项目名称:mongo-csharp-driver,代码行数:22,代码来源:NetPrimitiveSerializers.cs

示例11: Serialize

 public void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
 {
     if (value is decimal) {
         bsonWriter.WriteInt64((long)((decimal)value * 10000));
     }
 }
开发者ID:jawaharrajan,项目名称:IntroToMongoDBWithDotNet,代码行数:6,代码来源:DecimalSerializer.cs

示例12: if

 void IBsonSerializable.Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     IBsonSerializationOptions options
 )
 {
     bsonWriter.WriteStartDocument();
     bsonWriter.WriteString("$ref", collectionName);
     if (id is ObjectId) {
         var objectId = (ObjectId) id;
         bsonWriter.WriteObjectId("$id", objectId.Timestamp, objectId.Machine, objectId.Pid, objectId.Increment);
     } else if (id is Guid) {
         var guid = (Guid) id;
         bsonWriter.WriteBinaryData("$id", guid.ToByteArray(), BsonBinarySubType.Uuid);
     } else if (id is int) {
         bsonWriter.WriteInt32("$id", (int) id);
     } else if (id is long) {
         bsonWriter.WriteInt64("$id", (long) id);
     } else if (id is string) {
         bsonWriter.WriteString("$id", (string) id);
     } else {
         var message = string.Format("Unexpected Id type: {0}", id.GetType().FullName);
         throw new BsonInternalException(message);
     }
     if (databaseName != null) {
         bsonWriter.WriteString("$db", databaseName);
     }
     bsonWriter.WriteEndDocument();
 }
开发者ID:jenrom,项目名称:mongo-csharp-driver,代码行数:29,代码来源:MongoDBRef.cs

示例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 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);
     }
 }
开发者ID:kamaradclimber,项目名称:mongo-csharp-driver,代码行数:30,代码来源:NetPrimitiveSerializers.cs

示例14: Serialize

 public override void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     bool serializeIdFirst
 )
 {
     if (value == null) {
         bsonWriter.WriteNull();
     } else {
         bsonWriter.WriteInt64(((BsonInt64) value).Value);
     }
 }
开发者ID:kenegozi,项目名称:mongo-csharp-driver,代码行数:13,代码来源:BsonValueSerializers.cs

示例15: Serialize

 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);
     }
 }
开发者ID:daniaos,项目名称:mongo-csharp-driver,代码行数:27,代码来源:NetPrimitiveSerializers.cs


注:本文中的MongoDB.Bson.IO.BsonWriter.WriteInt64方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。