當前位置: 首頁>>代碼示例>>C#>>正文


C# BsonWriter.WriteInt32方法代碼示例

本文整理匯總了C#中MongoDB.Bson.IO.BsonWriter.WriteInt32方法的典型用法代碼示例。如果您正苦於以下問題:C# BsonWriter.WriteInt32方法的具體用法?C# BsonWriter.WriteInt32怎麽用?C# BsonWriter.WriteInt32使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在MongoDB.Bson.IO.BsonWriter的用法示例。


在下文中一共展示了BsonWriter.WriteInt32方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Serialize

		public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
		{
			if (value == null)
				bsonWriter.WriteInt32(0);
			else
				bsonWriter.WriteInt32(((ContentItem)value).ID);
		}
開發者ID:meixger,項目名稱:n2cms,代碼行數:7,代碼來源:ContentItemReferenceSerializer.cs

示例2: 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

示例3: Serialize

		public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
		{
			var relation = value as ContentRelation;

			if (relation == null || !relation.ID.HasValue || relation.ID.Value == 0)
				bsonWriter.WriteInt32(0);
			else
				bsonWriter.WriteInt32(relation.ID.Value);
		}
開發者ID:meixger,項目名稱:n2cms,代碼行數:9,代碼來源:ContentRelationSerializer.cs

示例4: Serialize

 public void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
 {
     var timeOfDay = (TimeOfDay)value;
     bsonWriter.WriteStartDocument();
     bsonWriter.WriteInt32("Hour", timeOfDay.Hour);
     bsonWriter.WriteInt32("Minute", timeOfDay.Minute);
     bsonWriter.WriteInt32("Second", timeOfDay.Second);
     bsonWriter.WriteEndDocument();
 }
開發者ID:Jiangew,項目名稱:quartz.net-mongodb,代碼行數:9,代碼來源:TimeOfDaySerializer.cs

示例5: Serialize

 public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
 {
     int intValue;
     if (value is string && int.TryParse((string)value, out intValue))
         bsonWriter.WriteInt32(intValue);
     else
         throw new InvalidOperationException();
 }
開發者ID:hitesh97,項目名稱:fluent-mongo,代碼行數:8,代碼來源:StringInt32Serializer.cs

示例6: Serialize

 public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
 {
     var c = (C)value;
     bsonWriter.WriteStartDocument();
     bsonWriter.WriteString("nominalType", nominalType.Name);
     bsonWriter.WriteInt32("X", c.X);
     bsonWriter.WriteEndDocument();
 }
開發者ID:rakesh-elevate,項目名稱:mongo-csharp-driver,代碼行數:8,代碼來源:BsonDocumentWrapperTests.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)
        {
            if (_trace)
                pb.Trace.WriteLine("ZIntSerializer.Serialize()");

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var zint = (ZInt)value;
            bsonWriter.WriteInt32(zint.Value);
        }
開發者ID:labeuze,項目名稱:source,代碼行數:20,代碼來源:ZIntSerializer.cs

示例8: 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:jarlef,項目名稱:Bifrost,代碼行數:23,代碼來源:ConceptSerializer.cs

示例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)
        {
            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

示例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 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

示例11: Serialize

#pragma warning restore 618

        /// <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 bitArray = (BitArray)value;
                var representationSerializationOptions = EnsureSerializationOptions<RepresentationSerializationOptions>(options);

                switch (representationSerializationOptions.Representation)
                {
                    case BsonType.Binary:
                        if ((bitArray.Length % 8) == 0)
                        {
                            bsonWriter.WriteBinaryData(GetBytes(bitArray), BsonBinarySubType.Binary);
                        }
                        else
                        {
                            bsonWriter.WriteStartDocument();
                            bsonWriter.WriteInt32("Length", bitArray.Length);
                            bsonWriter.WriteBinaryData("Bytes", GetBytes(bitArray), BsonBinarySubType.Binary);
                            bsonWriter.WriteEndDocument();
                        }
                        break;
                    case BsonType.String:
                        var sb = new StringBuilder(bitArray.Length);
                        for (int i = 0; i < bitArray.Length; i++)
                        {
                            sb.Append(bitArray[i] ? '1' : '0');
                        }
                        bsonWriter.WriteString(sb.ToString());
                        break;
                    default:
                        var message = string.Format("'{0}' is not a valid BitArray representation.", representationSerializationOptions.Representation);
                        throw new BsonSerializationException(message);
                }
            }
        }
開發者ID:davidxchen,項目名稱:mongo-csharp-driver,代碼行數:53,代碼來源:BitArraySerializer.cs

示例12: Serialize

 /// <summary>
 /// Serializes an object of type System.Drawing.Size  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 size = (System.Drawing.Size)value;
     bsonWriter.WriteStartDocument();
     bsonWriter.WriteInt32("Width", size.Width);
     bsonWriter.WriteInt32("Height", size.Height);
     bsonWriter.WriteEndDocument();
 }
開發者ID:abel,項目名稱:sinan,代碼行數:19,代碼來源:NetPrimitiveSerializers.cs

示例13: Serialize

 public override void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     IBsonSerializationOptions options
 )
 {
     var actualType = value.GetType();
     VerifySerializeTypes(nominalType, actualType);
     var representation = (options == null) ? 0 : ((RepresentationSerializationOptions) options).Representation;
     switch (representation) {
         case 0:
             var underlyingTypeCode = Type.GetTypeCode(Enum.GetUnderlyingType(actualType));
             if (underlyingTypeCode == TypeCode.Int64 || underlyingTypeCode == TypeCode.UInt64) {
                 goto case BsonType.Int64;
             } else {
                 goto case BsonType.Int32;
             }
         case BsonType.Int32:
             bsonWriter.WriteInt32(Convert.ToInt32(value));
             break;
         case BsonType.Int64:
             bsonWriter.WriteInt64(Convert.ToInt64(value));
             break;
         case BsonType.String:
             bsonWriter.WriteString(value.ToString());
             break;
         default:
             throw new BsonInternalException("Unexpected EnumRepresentation");
     }
 }
開發者ID:Teun,項目名稱:mongo-csharp-driver,代碼行數:31,代碼來源:EnumSerializer.cs

示例14: Serialize

 public override void Serialize(BsonWriter bsonWriter,
     Type nominalType, object value, IBsonSerializationOptions options) {
     Category category = value as Category;
     bsonWriter.WriteInt32(category.Id);
 }
開發者ID:kahinke,項目名稱:PingApp,代碼行數:5,代碼來源:CategorySerializer.cs

示例15: Serialize

 public override void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     bool serializeIdFirst
 )
 {
     bsonWriter.WriteInt32((int) value);
 }
開發者ID:tomthink,項目名稱:mongo-csharp-driver,代碼行數:9,代碼來源:BsonPrimitiveSerializers.cs


注:本文中的MongoDB.Bson.IO.BsonWriter.WriteInt32方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。