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


C# BsonWriter.WriteEndArray方法代码示例

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


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

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

示例2: Serialize

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

              var serializer = new StringSerializer();
              var nvc = (NameValueCollection) value;

              bsonWriter.WriteStartArray();
              foreach (var key in nvc.AllKeys)
              {
            foreach (var val in nvc.GetValues(key))
            {
              bsonWriter.WriteStartArray();
              serializer.Serialize(bsonWriter, typeof (string), key, options);
              serializer.Serialize(bsonWriter, typeof (string), val, options);
              bsonWriter.WriteEndArray();
            }
              }
              bsonWriter.WriteEndArray();
        }
开发者ID:TrueFit,项目名称:elmah-mongodb,代码行数:24,代码来源:NameValueCollectionSerializer.cs

示例3: Serialize

 public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
 {
     bsonWriter.WriteStartArray();
     if (value != null)
     {
         var array = value as IEnumerable;
         if (array != null)
         {
             foreach (var id in from object arrayItem in array select IdentifierFinder.GetId(arrayItem))
             {
                 BsonSerializer.Serialize(bsonWriter, id.GetType(), id);
             }
         }
     }
     bsonWriter.WriteEndArray();
 }
开发者ID:virajs,项目名称:MongoDB-Mapping-Attributes,代码行数:16,代码来源:OneToManyBsonSerializer.cs

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

示例5: 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 = (GeoJson3DProjectedCoordinates)value;

                bsonWriter.WriteStartArray();
                bsonWriter.WriteDouble(coordinates.Easting);
                bsonWriter.WriteDouble(coordinates.Northing);
                bsonWriter.WriteDouble(coordinates.Altitude);
                bsonWriter.WriteEndArray();
            }
        }
开发者ID:jlyonsmith,项目名称:mongo-csharp-driver,代码行数:24,代码来源:GeoJson3DProjectedCoordinatesSerializer.cs

示例6: Serialize

        public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
        {
            if (_trace)
                pb.Trace.WriteLine("ZStringArraySerializer.Serialize()");

            if (value == null)
            {
                throw new PBException("error serialize ZStringArray value is null");
            }

            string[] stringValues = ((ZStringArray)value).Values;

            if (stringValues == null)
                bsonWriter.WriteNull();
            else
            {
                bsonWriter.WriteStartArray();
                foreach (string stringValue in stringValues)
                {
                    bsonWriter.WriteString(stringValue);
                }
                bsonWriter.WriteEndArray();
            }
        }
开发者ID:labeuze,项目名称:source,代码行数:24,代码来源:ZStringArraySerializer.cs

示例7: 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
            {
                if (nominalType == typeof(object))
                {
                    var actualType = value.GetType();
                    bsonWriter.WriteStartDocument();
                    bsonWriter.WriteString("_t", TypeNameDiscriminator.GetDiscriminator(actualType));
                    bsonWriter.WriteName("_v");
                    Serialize(bsonWriter, actualType, value, options);
                    bsonWriter.WriteEndDocument();
                    return;
                }

                var items = ((Stack)value).ToArray(); // convert to array to allow efficient access in reverse order
                var arraySerializationOptions = EnsureSerializationOptions<ArraySerializationOptions>(options);
                var itemSerializationOptions = arraySerializationOptions.ItemSerializationOptions;

                // serialize first pushed item first (reverse of enumeration order)
                bsonWriter.WriteStartArray();
                for (var i = items.Length - 1; i >= 0; i--)
                {
                    BsonSerializer.Serialize(bsonWriter, typeof(object), items[i], itemSerializationOptions);
                }
                bsonWriter.WriteEndArray();
            }
        }
开发者ID:newlee,项目名称:mongo-csharp-driver,代码行数:43,代码来源:CollectionSerializers.cs

示例8: Serialize


//.........这里部分代码省略.........
            else
            {
                // dont know why nominalType can be an object
                if (nominalType == typeof(object))
                {
                    var actualType = value.GetType();
                    bsonWriter.WriteStartDocument();
                    bsonWriter.WriteString("_t", TypeNameDiscriminator.GetDiscriminator(actualType));
                    bsonWriter.WriteName("_v");
                    Serialize(bsonWriter, actualType, value, options); // recursive call replacing nominalType with actualType
                    bsonWriter.WriteEndDocument();
                    return;
                }

                // json Dictionary
                // { "toto1" : "tata1", "toto2" : "tata2" }

                //var dictionary = (IDictionary)value;
                NameValueCollection nameValueCollection = (NameValueCollection)value;
                var dictionarySerializationOptions = EnsureSerializationOptions(options);
                var dictionaryRepresentation = dictionarySerializationOptions.Representation;
                var keyValuePairSerializationOptions = dictionarySerializationOptions.KeyValuePairSerializationOptions;

                if (dictionaryRepresentation == DictionaryRepresentation.Dynamic)
                {
                    // if some keys contain '$', '.' or '\0' serialize as ArrayOfArrays otherwise serialize as Document
                    dictionaryRepresentation = DictionaryRepresentation.Document;
                    foreach (string key in nameValueCollection.Keys)
                    {
                        //var name = key as string; // key might not be a string
                        if (string.IsNullOrEmpty(key) || key[0] == '$' || key.IndexOf('.') != -1 || key.IndexOf('\0') != -1)
                        {
                            dictionaryRepresentation = DictionaryRepresentation.ArrayOfArrays;
                            break;
                        }
                    }
                }

                switch (dictionaryRepresentation)
                {
                    case DictionaryRepresentation.Document:
                        bsonWriter.WriteStartDocument();
                        //foreach (DictionaryEntry dictionaryEntry in dictionary)
                        //{
                        //    bsonWriter.WriteName((string)dictionaryEntry.Key);
                        //    BsonSerializer.Serialize(bsonWriter, typeof(object), dictionaryEntry.Value, keyValuePairSerializationOptions.ValueSerializationOptions);
                        //}
                        for (int i = 0; i < nameValueCollection.Count; i++)
                        {
                            bsonWriter.WriteString(nameValueCollection.GetKey(i), nameValueCollection.Get(i));
                        }
                        bsonWriter.WriteEndDocument();
                        break;

                    case DictionaryRepresentation.ArrayOfArrays:
                    case DictionaryRepresentation.ArrayOfDocuments:
                        // override KeyValuePair representation if necessary
                        var keyValuePairRepresentation = (dictionaryRepresentation == DictionaryRepresentation.ArrayOfArrays) ? BsonType.Array : BsonType.Document;
                        if (keyValuePairSerializationOptions.Representation != keyValuePairRepresentation)
                        {
                            keyValuePairSerializationOptions = new KeyValuePairSerializationOptions(keyValuePairRepresentation, keyValuePairSerializationOptions.KeySerializationOptions,
                                keyValuePairSerializationOptions.ValueSerializationOptions);
                        }

                        bsonWriter.WriteStartArray();
                        //foreach (DictionaryEntry dictionaryEntry in dictionary)
                        for (int i = 0; i < nameValueCollection.Count; i++)
                        {
                            //var keyValuePair = new KeyValuePair<object, object>(dictionaryEntry.Key, dictionaryEntry.Value);
                            var keyValuePair = new KeyValuePair<string, string>(nameValueCollection.GetKey(i), nameValueCollection.Get(i));
                            //_keyValuePairSerializer.Serialize(bsonWriter, typeof(KeyValuePair<object, object>), keyValuePair, keyValuePairSerializationOptions);
                            _keyValuePairSerializer.Serialize(bsonWriter, typeof(KeyValuePair<string, string>), keyValuePair, keyValuePairSerializationOptions);
                        }
                        bsonWriter.WriteEndArray();

                        //bsonWriter.WriteStartArray();
                        //for (int i = 0; i < nameValueCollection.Count; i++)
                        //{
                        //    bsonWriter.WriteStartArray();
                        //    bsonWriter.WriteString(nameValueCollection.GetKey(i), nameValueCollection.Get(i));
                        //    bsonWriter.WriteEndArray();
                        //}
                        //bsonWriter.WriteEndArray();
                        break;
                    //case DictionaryRepresentation.ArrayOfDocuments:
                    //    bsonWriter.WriteStartArray();
                    //    for (int i = 0; i < nameValueCollection.Count; i++)
                    //    {
                    //        bsonWriter.WriteStartDocument();
                    //        bsonWriter.WriteString(nameValueCollection.GetKey(i), nameValueCollection.Get(i));
                    //        bsonWriter.WriteEndDocument();
                    //    }
                    //    bsonWriter.WriteEndArray();
                    //    break;
                    default:
                        var message = string.Format("'{0}' is not a valid IDictionary representation.", dictionaryRepresentation);
                        throw new BsonSerializationException(message);
                }
            }
        }
开发者ID:labeuze,项目名称:source,代码行数:101,代码来源:NameValueCollectionSerializer.cs

示例9: 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 array = (BsonArray)value;
            bsonWriter.WriteStartArray();
            for (int i = 0; i < array.Count; i++)
            {
                BsonValueSerializer.Instance.Serialize(bsonWriter, typeof(BsonValue), array[i], null);
            }
            bsonWriter.WriteEndArray();
        }
开发者ID:robinNode,项目名称:mongo-csharp-driver,代码行数:26,代码来源:BsonArraySerializer.cs

示例10: Serialize

 public override void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     IBsonSerializationOptions options
 )
 {
     if (value == null) {
         bsonWriter.WriteNull();
     } else {
         var dictionary = (IDictionary) value;
         if (dictionary.Keys.Cast<object>().All(o => o.GetType() == typeof(string))) {
             bsonWriter.WriteStartDocument();
             int index = 0;
             foreach (DictionaryEntry entry in dictionary) {
                 bsonWriter.WriteName((string) entry.Key);
                 BsonSerializer.Serialize(bsonWriter, typeof(object), entry.Value);
                 index++;
             }
             bsonWriter.WriteEndDocument();
         } else {
             bsonWriter.WriteStartArray();
             foreach (DictionaryEntry entry in dictionary) {
                 bsonWriter.WriteStartArray();
                 BsonSerializer.Serialize(bsonWriter, typeof(object), entry.Key);
                 BsonSerializer.Serialize(bsonWriter, typeof(object), entry.Value);
                 bsonWriter.WriteEndArray();
             }
             bsonWriter.WriteEndArray();
        }
     }
 }
开发者ID:kolupaev,项目名称:mongo-csharp-driver,代码行数:32,代码来源:DictionarySerializer.cs

示例11: Serialize

 public override void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     IBsonSerializationOptions options
 ) {
     var decimalValue = (Decimal) value;
     var representation = (options == null) ? BsonType.String : ((RepresentationSerializationOptions) options).Representation;
     switch (representation) {
         case BsonType.Array:
             bsonWriter.WriteStartArray();
             var bits = Decimal.GetBits(decimalValue);
             bsonWriter.WriteInt32("0", bits[0]);
             bsonWriter.WriteInt32("1", bits[1]);
             bsonWriter.WriteInt32("2", bits[2]);
             bsonWriter.WriteInt32("3", bits[3]);
             bsonWriter.WriteEndArray();
             break;
         case BsonType.String:
             bsonWriter.WriteString(XmlConvert.ToString(decimalValue));
             break;
         default:
             var message = string.Format("'{0}' is not a valid representation for type 'Decimal'", representation);
             throw new BsonSerializationException(message);
     }
 }
开发者ID:daniaos,项目名称:mongo-csharp-driver,代码行数:26,代码来源:NetPrimitiveSerializers.cs

示例12: SerializePolygon

 private static void SerializePolygon(BsonWriter bsonWriter, OXmlPolygon polygon)
 {
     bsonWriter.WriteStartDocument("Polygon");
     if (polygon.StartPoint != null)
     {
         bsonWriter.WriteInt64("StartPointX", polygon.StartPoint.X);
         bsonWriter.WriteInt64("StartPointY", polygon.StartPoint.Y);
     }
     bsonWriter.WriteStartArray("LinesTo");
     foreach (OXmlPoint2DType lineTo in polygon.LinesTo)
     {
         bsonWriter.WriteStartDocument();
         bsonWriter.WriteInt64("X", lineTo.X);
         bsonWriter.WriteInt64("Y", lineTo.Y);
         bsonWriter.WriteEndDocument();
     }
     bsonWriter.WriteEndArray();
     if (polygon.Edited != null)
         bsonWriter.WriteBoolean("Edited", (bool)polygon.Edited);
     bsonWriter.WriteEndDocument();
 }
开发者ID:labeuze,项目名称:source,代码行数:21,代码来源:OXmlPictureElementSerializer.cs

示例13: 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
            {
                if (nominalType == typeof(object))
                {
                    var actualType = value.GetType();
                    bsonWriter.WriteStartDocument();
                    bsonWriter.WriteString("_t", TypeNameDiscriminator.GetDiscriminator(actualType));
                    bsonWriter.WriteName("_v");
                    Serialize(bsonWriter, actualType, value, options); // recursive call replacing nominalType with actualType
                    bsonWriter.WriteEndDocument();
                    return;
                }

                var dictionary = (IDictionary)value;
                var dictionarySerializationOptions = EnsureSerializationOptions(options);
                var dictionaryRepresentation = dictionarySerializationOptions.Representation;
                var keyValuePairSerializationOptions = dictionarySerializationOptions.KeyValuePairSerializationOptions;

                if (dictionaryRepresentation == DictionaryRepresentation.Dynamic)
                {
                    dictionaryRepresentation = DictionaryRepresentation.Document;
                    foreach (object key in dictionary.Keys)
                    {
                        var name = key as string; // key might not be a string
                        if (name == null || (name.Length > 0 && name[0] == '$') || name.IndexOf('.') != -1)
                        {
                            dictionaryRepresentation = DictionaryRepresentation.ArrayOfArrays;
                            break;
                        }
                    }
                }

                switch (dictionaryRepresentation)
                {
                    case DictionaryRepresentation.Document:
                        bsonWriter.WriteStartDocument();
                        foreach (DictionaryEntry dictionaryEntry in dictionary)
                        {
                            bsonWriter.WriteName((string)dictionaryEntry.Key);
                            BsonSerializer.Serialize(bsonWriter, typeof(object), dictionaryEntry.Value, keyValuePairSerializationOptions.ValueSerializationOptions);
                        }
                        bsonWriter.WriteEndDocument();
                        break;

                    case DictionaryRepresentation.ArrayOfArrays:
                    case DictionaryRepresentation.ArrayOfDocuments:
                        // override KeyValuePair representation if necessary
                        var keyValuePairRepresentation = (dictionaryRepresentation == DictionaryRepresentation.ArrayOfArrays) ? BsonType.Array : BsonType.Document;
                        if (keyValuePairSerializationOptions.Representation != keyValuePairRepresentation)
                        {
                            keyValuePairSerializationOptions = new KeyValuePairSerializationOptions(
                                keyValuePairRepresentation,
                                keyValuePairSerializationOptions.KeySerializationOptions,
                                keyValuePairSerializationOptions.ValueSerializationOptions);
                        }

                        bsonWriter.WriteStartArray();
                        foreach (DictionaryEntry dictionaryEntry in dictionary)
                        {
                            var keyValuePair = new KeyValuePair<object, object>(dictionaryEntry.Key, dictionaryEntry.Value);
                            _keyValuePairSerializer.Serialize(
                                bsonWriter,
                                typeof(KeyValuePair<object, object>),
                                keyValuePair,
                                keyValuePairSerializationOptions);
                        }
                        bsonWriter.WriteEndArray();
                        break;
                    default:
                        var message = string.Format("'{0}' is not a valid IDictionary representation.", dictionaryRepresentation);
                        throw new BsonSerializationException(message);
                }
            }
        }
开发者ID:CloudMetal,项目名称:mongo-csharp-driver,代码行数:91,代码来源:DictionarySerializer.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)
     {
         bsonWriter.WriteNull();
     }
     else
     {
         bsonWriter.WriteStartArray();
         foreach (var element in (Queue)value)
         {
             BsonSerializer.Serialize(bsonWriter, typeof(object), element);
         }
         bsonWriter.WriteEndArray();
     }
 }
开发者ID:moonreplace,项目名称:mongo-csharp-driver,代码行数:23,代码来源:CollectionSerializers.cs

示例15: Serialize

 public override void Serialize(
     BsonWriter bsonWriter,
     Type nominalType,
     object value,
     bool serializeIdFirst
 )
 {
     if (value == null) {
         bsonWriter.WriteNull();
     } else {
         bsonWriter.WriteStartArray();
         int index = 0;
         foreach (var element in (IEnumerable) value) {
             bsonWriter.WriteName(index.ToString());
             BsonSerializer.Serialize(bsonWriter, typeof(object), element);
             index++;
         }
         bsonWriter.WriteEndArray();
     }
 }
开发者ID:kenegozi,项目名称:mongo-csharp-driver,代码行数:20,代码来源:CollectionSerializers.cs


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