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


C# BsonWriter.WriteNull方法代碼示例

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


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

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

示例2: Serialize

        public override void Serialize(
			BsonWriter bsonWriter,
			Type nominalType,
			object value,
			IBsonSerializationOptions options
			)
        {
            if (value == null)
            {
                bsonWriter.WriteNull();
                return;
            }

            var nvc = (NameValueCollection)value;

            bsonWriter.WriteStartArray();
            foreach (var key in nvc.AllKeys)
            {
                foreach (var val in nvc.GetValues(key))
                {
                    bsonWriter.WriteStartArray();
                    StringSerializer.Instance.Serialize(bsonWriter, typeof(string), key, options);
                    StringSerializer.Instance.Serialize(bsonWriter, typeof(string), val, options);
                    bsonWriter.WriteEndArray();
                }
            }
            bsonWriter.WriteEndArray();
        }
開發者ID:CaptainCodeman,項目名稱:elmah-mongodb,代碼行數:28,代碼來源:NameValueCollectionSerializer.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)
     {
         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

示例4: Serialize

        public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
        {
            IDictionary<string, object> obj = value as IDictionary<string, object>;
            if (obj == null)
            {
                bsonWriter.WriteNull();
                return;
            }

            bsonWriter.WriteStartDocument();
            foreach (var member in obj)
            {
                bsonWriter.WriteName(member.Key);
                object memberValue = member.Value;

                if (memberValue == null)
                {
                    bsonWriter.WriteNull();
                }
                else
                {
                    nominalType = memberValue.GetType();
                    var serializer = BsonSerializer.LookupSerializer(nominalType);
                    serializer.Serialize(bsonWriter, nominalType, memberValue, options);
                }
            }
            bsonWriter.WriteEndDocument();
        }
開發者ID:abel,項目名稱:sinan,代碼行數:28,代碼來源:VariantBsonSerializer.cs

示例5: Serialize

 public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
 {
     if (value == null)
     {
         bsonWriter.WriteNull();
     }
     else
     {
         ObjectIdSerializer.Instance.Serialize(bsonWriter, nominalType, IdentifierFinder.GetId(value), options);
     }
 }
開發者ID:virajs,項目名稱:MongoDB-Mapping-Attributes,代碼行數:11,代碼來源:ManyToOneBsonSerializer.cs

示例6: Serialize

		public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
		{
			if (value == null)
			{
				bsonWriter.WriteNull();
			}
			else
			{
				var attachment = (Attachment)value;
				ObjectIdSerializer.Instance.Serialize(bsonWriter, nominalType, attachment.ID, options);
			}
		}
開發者ID:modulexcite,項目名稱:ormongo,代碼行數:12,代碼來源:AttachmentSerializer.cs

示例7: Serialize

 public override void Serialize(BsonWriter bsonWriter, Type nominalType,
     object value, IBsonSerializationOptions options)
 {
     if (value != null)
     {
         bsonWriter.WriteString(value.ToString());
     }
     else
     {
         bsonWriter.WriteNull();
     }
 }
開發者ID:neoms21,項目名稱:FeelKnit.Service,代碼行數:12,代碼來源:StringOrGuidSerializer.cs

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

示例9: Serialize

 public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
 {
     if (value == null)
     {
         bsonWriter.WriteNull();
     }
     else
     {
         var actualType = value.GetType();
         var actualTypeSerializer = BsonSerializer.LookupSerializer(actualType);
         actualTypeSerializer.Serialize(bsonWriter, nominalType, value, options);
     }
 }
開發者ID:pwelter34,項目名稱:mongo-csharp-driver,代碼行數:13,代碼來源:GeoJsonCoordinateReferenceSystemSerializer.cs

示例10: WriteNullableDouble

        protected void WriteNullableDouble(BsonWriter writer,string name,double? value)
        {
            writer.WriteName(name);

            if ( value != null )
            {
                writer.WriteDouble(value.Value);
            }
            else
            {
                writer.WriteNull();
            }
        }
開發者ID:BernhardGlueck,項目名稱:Phare,代碼行數:13,代碼來源:MongoDbSerializerBase.cs

示例11: Serialize

 public override void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     bool serializeIdFirst
 )
 {
     if (value == null) {
         bsonWriter.WriteNull();
     } else {
         ((BsonArray) value).WriteTo(bsonWriter);
     }
 }
開發者ID:kenegozi,項目名稱:mongo-csharp-driver,代碼行數:13,代碼來源:BsonValueSerializers.cs

示例12: Serialize

 public override void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     bool serializeIdFirst
 )
 {
     if (value == null) {
         bsonWriter.WriteNull();
     } else {
         Type underlyingType = Nullable.GetUnderlyingType(nominalType);
         BsonSerializer.Serialize(bsonWriter, underlyingType, value, serializeIdFirst);
     }
 }
開發者ID:tomthink,項目名稱:mongo-csharp-driver,代碼行數:14,代碼來源:NullableTypeSerializer.cs

示例13: Serialize

        public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
        {
            if (value == null)
            {
                throw new PBException("error serialize UrlImage value is null");
            }

            //bsonWriter.WriteString(((WebImage)value).Url);
            string url = ((WebImage)value).Url;
            if (url != null)
                bsonWriter.WriteString(url);
            else
                bsonWriter.WriteNull();
        }
開發者ID:labeuze,項目名稱:source,代碼行數:14,代碼來源:UrlImageSerializer.cs

示例14: Serialize

        public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
        {
            // when entry is null, do not throw, just write null
            if (value == null)
            {
                bsonWriter.WriteNull();
                return;
            }

            if (_failOnSerialize)
                throw new InvalidOperationException();

            bsonWriter.WriteString((string)value);
        }
開發者ID:hitesh97,項目名稱:fluent-mongo,代碼行數:14,代碼來源:FailingStringSerializer.cs

示例15: 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();
            }
        }
開發者ID:Khosrow-Azizi,項目名稱:MasterExperimentV2,代碼行數:23,代碼來源:GeoJson2DCoordinatesSerializer.cs


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