当前位置: 首页>>代码示例>>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;未经允许,请勿转载。