当前位置: 首页>>代码示例>>C#>>正文


C# BsonWriter.WriteStartDocument方法代码示例

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


在下文中一共展示了BsonWriter.WriteStartDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

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

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

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

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

示例6: Serialize

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

                bsonWriter.WriteStartDocument();
                SerializeType(bsonWriter, crs.Type);
                bsonWriter.WriteStartDocument("properties");
                bsonWriter.WriteString("name", crs.Name);
                bsonWriter.WriteEndDocument();
                bsonWriter.WriteEndDocument();
            }
        }
开发者ID:pwelter34,项目名称:mongo-csharp-driver,代码行数:18,代码来源:GeoJsonNamedCoordinateReferenceSystemSerializer.cs

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

示例8: Serialize

        public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
        {
            if (value == null)
                throw new PBException("serialize OXmlSimpleFieldElement value is null");
            if (_trace)
                pb.Trace.WriteLine("OXmlSimpleFieldElementSerializer.Serialize()");

            OXmlSimpleFieldElement element = (OXmlSimpleFieldElement)value;
            bsonWriter.WriteStartDocument();
            bsonWriter.WriteString("Type", "SimpleField");
            bsonWriter.WriteString("Instruction", element.Instruction);
            bsonWriter.WriteEndDocument();
        }
开发者ID:labeuze,项目名称:source,代码行数:13,代码来源:OXmlSimpleFieldElementSerializer.cs

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

示例10: Serialize

        public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
        {
            if (value == null)
                throw new PBException("serialize OXmlOpenHeader value is null");
            if (_trace)
                pb.Trace.WriteLine("OXmlOpenHeaderElementSerializer.Serialize()");

            OXmlOpenHeaderElement element = (OXmlOpenHeaderElement)value;
            bsonWriter.WriteStartDocument();
            bsonWriter.WriteString("Type", "OpenHeader");
            bsonWriter.WriteString("HeaderType", element.HeaderType.ToString());
            bsonWriter.WriteEndDocument();
        }
开发者ID:labeuze,项目名称:source,代码行数:13,代码来源:OXmlOpenHeaderElementSerializer.cs

示例11: Serialize

        public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
        {
            if (value == null)
                throw new PBException("serialize OXmlParagraphElement value is null");
            if (_trace)
                pb.Trace.WriteLine("OXmlParagraphElementSerializer.Serialize()");

            OXmlParagraphElement paragraph = (OXmlParagraphElement)value;
            bsonWriter.WriteStartDocument();
            bsonWriter.WriteString("Type", "Paragraph");
            if (paragraph.Style != null)
                bsonWriter.WriteString("Style", paragraph.Style);
            bsonWriter.WriteEndDocument();
        }
开发者ID:labeuze,项目名称:source,代码行数:14,代码来源:OXmlParagraphElementSerializer.cs

示例12: Serialize

        public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
        {
            if (value == null)
                throw new PBException("serialize OXmlTextElement value is null");
            if (_trace)
                pb.Trace.WriteLine("OXmlTextElementSerializer.Serialize()");

            OXmlTextElement element = (OXmlTextElement)value;
            bsonWriter.WriteStartDocument();
            bsonWriter.WriteString("Type", "Text");
            if (element.Text != null)
                bsonWriter.WriteString("Text", element.Text);
            if (element.PreserveSpace)
                bsonWriter.WriteBoolean("PreserveSpace", element.PreserveSpace);
            bsonWriter.WriteEndDocument();
        }
开发者ID:labeuze,项目名称:source,代码行数:16,代码来源:OXmlTextElementSerializer.cs

示例13: Serialize

        public override void Serialize(
			BsonWriter bsonWriter,
			Type nominalType,
			object value,
			IBsonSerializationOptions options
			)
        {
            var nvc = (NameValueCollection)value;
            bsonWriter.WriteStartDocument();
            if (nvc != null && nvc.Count > 0)
            {
                foreach (var key in nvc.AllKeys)
                {
                    bsonWriter.WriteString(key.Replace(".", "__period__"), nvc[key]);
                }
            }
            bsonWriter.WriteEndDocument();
        }
开发者ID:JefClaes,项目名称:elmah-mongodb,代码行数:18,代码来源:NameValueCollectionSerializer.cs

示例14: Serialize

        public override void Serialize( BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options )
        {
            var dictionary = (DynamicDictionary)value;

            bsonWriter.WriteStartDocument();

            bsonWriter.WriteString( "_t", "DynamicDictionary" );

            if( dictionary != null )
            {
                foreach( var entry in dictionary )
                {
                    bsonWriter.WriteName( entry.Key.Replace( '.', '\x03' ) );
                    BsonSerializer.Serialize( bsonWriter, typeof( object ), entry.Value );
                }
            }

            bsonWriter.WriteEndDocument();
        }
开发者ID:RabidArts,项目名称:TrivialMongoMessageQueue,代码行数:19,代码来源:DynamicDictionarySerializer.cs

示例15: Serialize

        public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
        {
            if (value == null)
                throw new PBException("serialize OXmlDocDefaultsRunPropertiesElement value is null");
            if (_trace)
                pb.Trace.WriteLine("OXmlRunPropertiesDefaultElementSerializer.Serialize()");

            OXmlDocDefaultsRunPropertiesElement element = (OXmlDocDefaultsRunPropertiesElement)value;
            bsonWriter.WriteStartDocument();

            bsonWriter.WriteString("Type", "DocDefaultsRunProperties");

            if (element.RunFonts != null)
            {
                bsonWriter.WriteStartDocument("RunFonts");
                OXmlCommonSerializer.WriteRunFonts(bsonWriter, element.RunFonts);
                bsonWriter.WriteEndDocument();
            }

            if (element.FontSize != null)
                bsonWriter.WriteString("FontSize", element.FontSize);

            bsonWriter.WriteEndDocument();
        }
开发者ID:labeuze,项目名称:source,代码行数:24,代码来源:OXmlDocDefaultsRunPropertiesElementSerializer.cs


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