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


C# IO.BsonWriter類代碼示例

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


BsonWriter類屬於MongoDB.Bson.IO命名空間,在下文中一共展示了BsonWriter類的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

 /// <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 lazyBsonArray = (LazyBsonArray)value;
         var slice = lazyBsonArray.Slice;
         if (slice == null)
         {
             BsonArraySerializer.Instance.Serialize(bsonWriter, typeof(BsonArray), lazyBsonArray, options);
         }
         else
         {
             using (var clonedSlice = slice.GetSlice(0, slice.Length))
             {
                 bsonWriter.WriteRawBsonArray(clonedSlice);
             }
         }
     }
 }
開發者ID:Khosrow-Azizi,項目名稱:MasterExperimentV2,代碼行數:34,代碼來源:LazyBsonArraySerializer.cs

示例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)
            {
                throw new ArgumentNullException("value");
            }

            var wrapper = (BsonDocumentWrapper)value;
            if (wrapper.IsUpdateDocument)
            {
                var savedCheckElementNames = bsonWriter.CheckElementNames;
                var savedCheckUpdateDocument = bsonWriter.CheckUpdateDocument;
                try
                {
                    bsonWriter.CheckElementNames = false;
                    bsonWriter.CheckUpdateDocument = true;
                    BsonSerializer.Serialize(bsonWriter, wrapper.WrappedNominalType, wrapper.WrappedObject, null); // TODO: wrap options also?
                }
                finally
                {
                    bsonWriter.CheckElementNames = savedCheckElementNames;
                    bsonWriter.CheckUpdateDocument = savedCheckUpdateDocument;
                }
            }
            else
            {
                BsonSerializer.Serialize(bsonWriter, wrapper.WrappedNominalType, wrapper.WrappedObject, null); // TODO: wrap options also?
            }
        }
開發者ID:CloudMetal,項目名稱:mongo-csharp-driver,代碼行數:40,代碼來源:BsonDocumentWrapperSerializer.cs

示例4: Serialize

        public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
        {
            if (value == null)
            {
                bsonWriter.WriteNull();
                return;
            }
            var metaObject = ((IDynamicMetaObjectProvider)value).GetMetaObject(Expression.Constant(value));
            var memberNames = metaObject.GetDynamicMemberNames().ToList();
            if (memberNames.Count == 0)
            {
                bsonWriter.WriteNull();
                return;
            }

            bsonWriter.WriteStartDocument();
            foreach (var memberName in memberNames)
            {
                bsonWriter.WriteName(memberName);
                var memberValue = BinderHelper.GetMemberValue(value, memberName);
                if (memberValue == null)
                    bsonWriter.WriteNull();
                else
                {
                    var memberType = memberValue.GetType();
                    var serializer = BsonSerializer.LookupSerializer(memberType);
                    serializer.Serialize(bsonWriter, memberType, memberValue, options);
                }
            }
            bsonWriter.WriteEndDocument();
        }
開發者ID:BraveNewMath,項目名稱:Simple.Data.MongoDB,代碼行數:31,代碼來源:DynamicBsonSerializer.cs

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

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

示例7: Serialize

 public virtual void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     bool serializeIdFirst
 )
 {
     throw new InvalidOperationException("Subclass must implement Serialize");
 }
開發者ID:testn,項目名稱:mongo-csharp-driver,代碼行數:9,代碼來源:BsonBaseSerializer.cs

示例8: Serialize

 public virtual void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     IBsonSerializationOptions options
 )
 {
     throw new InvalidOperationException("Subclass must implement Serialize");
 }
開發者ID:modesto,項目名稱:mongo-csharp-driver,代碼行數:9,代碼來源:BsonBaseSerializer.cs

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

示例10: Serialize

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

示例11: Serialize

        public override void Serialize(
			BsonWriter bsonWriter,
			Type nominalType,
			object value,
			IBsonSerializationOptions options
			)
        {
            var type = (Type)value;
            bsonWriter.WriteString(type.AssemblyQualifiedName);
        }
開發者ID:CaptainCodeman,項目名稱:quartznet,代碼行數:10,代碼來源:TypeSerializer.cs

示例12: 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();
        }
開發者ID:BernhardGlueck,項目名稱:Phare,代碼行數:12,代碼來源:RectangleBsonSerializer.cs

示例13: Serialize

        #pragma warning restore 618

        public override void Serialize(
            BsonWriter bsonWriter,
            Type nominalType,
            object value,
            bool serializeIdFirst
        ) {
            if (value == null) {
                bsonWriter.WriteNull();
            } else {
                bsonWriter.WriteBinaryData((byte[]) value, BsonBinarySubType.Binary);
            }
        }
開發者ID:testn,項目名稱:mongo-csharp-driver,代碼行數:14,代碼來源:NetPrimitiveSerializers.cs

示例14: 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");
            }

            bsonWriter.WriteUndefined();
        }
開發者ID:egametang,項目名稱:Egametang,代碼行數:20,代碼來源:BsonUndefinedSerializer.cs

示例15: Serialize

        public void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
        {
            var method = (MethodInfo)value;

            bsonWriter.WriteStartDocument();
            bsonWriter.WriteName("Type");
            bsonWriter.WriteString(method.DeclaringType.AssemblyQualifiedName);
            bsonWriter.WriteName("Method");
            bsonWriter.WriteString(GetMethodSignature(method));

            bsonWriter.WriteEndDocument();

        }
開發者ID:LenFon,項目名稱:Bifrost,代碼行數:13,代碼來源:MethodInfoSerializer.cs


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