• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IO.BsonWriter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



BsonWriter类属于MongoDB.Bson.IO命名空间,在下文中一共展示了BsonWriter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: 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 script = (BsonJavaScript)value;
            bsonWriter.WriteJavaScript(script.Code);
        }
开发者ID:CloudMetal,项目名称:mongo-csharp-driver,代码行数:21,代码来源:BsonJavaScriptSerializer.cs


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


示例18: 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 symbol = (BsonSymbol)value;
            bsonWriter.WriteSymbol(symbol.Name);
        }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:21,代码来源:BsonSymbolSerializer.cs


示例19: 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 timestamp = (BsonTimestamp)value;
            bsonWriter.WriteTimestamp(timestamp.Value);
        }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:21,代码来源:BsonTimestampSerializer.cs


示例20: 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 objectId = ((BsonObjectId)value).Value;
            bsonWriter.WriteObjectId(objectId);
        }
开发者ID:egametang,项目名称:Egametang,代码行数:21,代码来源:BsonObjectIdSerializer.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IO.JsonBuffer类代码示例发布时间:2022-05-26
下一篇:
C# IO.BsonStreamAdapter类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap