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


C# BsonReader.ReadEndDocument方法代码示例

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


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

示例1: Deserialize

        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>
        /// An object.
        /// </returns>
        public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
        {
            if (bsonReader.GetCurrentBsonType() == BsonType.Null)
            {
                bsonReader.ReadNull();
                return null;
            }
            else
            {
                bsonReader.ReadStartDocument();
                DeserializeType(bsonReader, "link");
                bsonReader.ReadName("properties");
                bsonReader.ReadStartDocument();
                var href = bsonReader.ReadString("href");
                string hrefType = null;
                if (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
                {
                    hrefType = bsonReader.ReadString("type");
                }
                bsonReader.ReadEndDocument();
                bsonReader.ReadEndDocument();

                return new GeoJsonLinkedCoordinateReferenceSystem(href, hrefType);
            }
        }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:36,代码来源:GeoJsonLinkedCoordinateReferenceSystemSerializer.cs

示例2: Deserialize

        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(BsonNull));

            var bsonType = bsonReader.GetCurrentBsonType();
            string message;
            switch (bsonType)
            {
                case BsonType.Null:
                    bsonReader.ReadNull();
                    return BsonNull.Value;
                case BsonType.Document:
                    bsonReader.ReadStartDocument();
                    var name = bsonReader.ReadName();
                    if (name == "_csharpnull" || name == "$csharpnull")
                    {
                        var csharpNull = bsonReader.ReadBoolean();
                        bsonReader.ReadEndDocument();
                        return csharpNull ? null : BsonNull.Value;
                    }
                    else
                    {
                        message = string.Format("Unexpected element name while deserializing a BsonNull: {0}.", name);
                        throw new FileFormatException(message);
                    }
                default:
                    message = string.Format("Cannot deserialize BsonNull from BsonType {0}.", bsonType);
                    throw new FileFormatException(message);
            }
        }
开发者ID:andreabalducci,项目名称:mongo-csharp-driver,代码行数:43,代码来源:BsonNullSerializer.cs

示例3: Deserialize

        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(CultureInfo));

            var bsonType = bsonReader.GetCurrentBsonType();
            switch (bsonType)
            {
                case BsonType.Null:
                    bsonReader.ReadNull();
                    return null;
                case BsonType.Document:
                    bsonReader.ReadStartDocument();
                    var name = bsonReader.ReadString("Name");
                    var useUserOverride = bsonReader.ReadBoolean("UseUserOverride");
                    bsonReader.ReadEndDocument();
                    return new CultureInfo(name, useUserOverride);
                case BsonType.String:
                    return new CultureInfo(bsonReader.ReadString());
                default:
                    var message = string.Format("Cannot deserialize CultureInfo from BsonType {0}.", bsonType);
                    throw new FileFormatException(message);
            }
        }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:36,代码来源:CultureInfoSerializer.cs

示例4: Deserialize

        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            IBsonSerializationOptions options
        ) {
            if (nominalType != typeof(object)) {
                var message = string.Format("ObjectSerializer called for nominal type {0}.", nominalType.FullName);
                throw new InvalidOperationException(message);
            }

            var bsonType = bsonReader.CurrentBsonType;
            if (bsonType == BsonType.Null) {
                bsonReader.ReadNull();
                return null;
            } else if (bsonType == BsonType.Document) {
                var bookmark = bsonReader.GetBookmark();
                bsonReader.ReadStartDocument();
                if (bsonReader.ReadBsonType() == BsonType.EndOfDocument) {
                    bsonReader.ReadEndDocument();
                    return new object();
                } else {
                    bsonReader.ReturnToBookmark(bookmark);
                }
            }

            var discriminatorConvention = BsonDefaultSerializer.LookupDiscriminatorConvention(typeof(object));
            var actualType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
            if (actualType == typeof(object)) {
                var message = string.Format("Unable to determine actual type of object to deserialize. NominalType is System.Object and BsonType is {0}.", bsonType);
                throw new FileFormatException(message);
            }
            var serializer = BsonSerializer.LookupSerializer(actualType);
            return serializer.Deserialize(bsonReader, nominalType, actualType, null);
        }
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:41,代码来源:ObjectSerializer.cs

示例5: Deserialize

        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(DateTimeOffset));

            BsonType bsonType = bsonReader.GetCurrentBsonType();
            long ticks;
            TimeSpan offset;
            switch (bsonType)
            {
                case BsonType.Array:
                    bsonReader.ReadStartArray();
                    ticks = bsonReader.ReadInt64();
                    offset = TimeSpan.FromMinutes(bsonReader.ReadInt32());
                    bsonReader.ReadEndArray();
                    return new DateTimeOffset(ticks, offset);
                case BsonType.Document:
                    bsonReader.ReadStartDocument();
                    bsonReader.ReadDateTime("DateTime"); // ignore value
                    ticks = bsonReader.ReadInt64("Ticks");
                    offset = TimeSpan.FromMinutes(bsonReader.ReadInt32("Offset"));
                    bsonReader.ReadEndDocument();
                    return new DateTimeOffset(ticks, offset);
                case BsonType.String:
                    return XmlConvert.ToDateTimeOffset(bsonReader.ReadString());
                default:
                    var message = string.Format("Cannot deserialize DateTimeOffset from BsonType {0}.", bsonType);
                    throw new Exception(message);
            }
        }
开发者ID:egametang,项目名称:Egametang,代码行数:42,代码来源:DateTimeOffsetSerializer.cs

示例6: Deserialize

 #pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary
 public override object Deserialize(
     BsonReader bsonReader,
     Type nominalType,
     IBsonSerializationOptions options
 ) {
     BsonType bsonType = bsonReader.CurrentBsonType;
     BitArray bitArray;
     byte[] bytes;
     BsonBinarySubType subType;
     string message;
     switch (bsonType) {
         case BsonType.Null:
             bsonReader.ReadNull();
             return null;
         case BsonType.Binary:
             bsonReader.ReadBinaryData(out bytes, out subType);
             if (subType != BsonBinarySubType.Binary && subType != BsonBinarySubType.OldBinary) {
                 message = string.Format("Invalid Binary sub type: {0}", subType);
                 throw new FileFormatException(message);
             }
             return new BitArray(bytes);
         case BsonType.Document:
             bsonReader.ReadStartDocument();
             var length = bsonReader.ReadInt32("Length");
             bsonReader.ReadBinaryData("Bytes", out bytes, out subType);
             if (subType != BsonBinarySubType.Binary && subType != BsonBinarySubType.OldBinary) {
                 message = string.Format("Invalid Binary sub type: {0}", subType);
                 throw new FileFormatException(message);
             }
             bsonReader.ReadEndDocument();
             bitArray = new BitArray(bytes);
             bitArray.Length = length;
             return bitArray;
         case BsonType.String:
             var s = bsonReader.ReadString();
             bitArray = new BitArray(s.Length);
             for (int i = 0; i < s.Length; i++) {
                 var c = s[i];
                 switch (c) {
                     case '0':
                         break;
                     case '1':
                         bitArray[i] = true;
                         break;
                     default:
                         throw new FileFormatException("String value is not a valid BitArray");
                 }
             }
             return bitArray;
         default:
             message = string.Format("Cannot deserialize Byte[] from BsonType: {0}", bsonType);
             throw new FileFormatException(message);
     }
 }
开发者ID:daniaos,项目名称:mongo-csharp-driver,代码行数:55,代码来源:NetPrimitiveSerializers.cs

示例7: Deserialize

        // public methods
        public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
        {
            if (bsonReader.GetCurrentBsonType() == BsonType.Null)
            {
                bsonReader.ReadNull();
                return null;
            }
            else
            {
                bsonReader.ReadStartDocument();
                DeserializeType(bsonReader, "name");
                bsonReader.ReadName("properties");
                bsonReader.ReadStartDocument();
                var name = bsonReader.ReadString("name");
                bsonReader.ReadEndDocument();
                bsonReader.ReadEndDocument();

                return new GeoJsonNamedCoordinateReferenceSystem(name);
            }
        }
开发者ID:pwelter34,项目名称:mongo-csharp-driver,代码行数:21,代码来源:GeoJsonNamedCoordinateReferenceSystemSerializer.cs

示例8: Deserialize

        public override object Deserialize(BsonReader bsonReader, System.Type nominalType, System.Type actualType, IBsonSerializationOptions options)
        {
            bsonReader.ReadStartDocument();

            var min     = ReadVector(bsonReader, "Min");
            var max     = ReadVector(bsonReader, "Max");
            var width   = bsonReader.ReadDouble("Width");
            var height  = bsonReader.ReadDouble("Height");

            bsonReader.ReadEndDocument();

            return new Rectangle(min, max);
        }
开发者ID:BernhardGlueck,项目名称:Phare,代码行数:13,代码来源:RectangleBsonSerializer.cs

示例9: Deserialize

        public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
        {
            if (_trace)
                pb.Trace.WriteLine("OXmlSimpleFieldElementSerializer.Deserialize()");

            VerifyTypes(nominalType, actualType, typeof(OXmlSimpleFieldElement));

            var bsonType = bsonReader.GetCurrentBsonType();
            if (bsonType != BsonType.Document)
                throw new PBException($"deserialize OXmlSimpleFieldElement, invalid BsonType {bsonType}.");
            bsonReader.ReadStartDocument();
            object value = _Deserialize(bsonReader, options);
            bsonReader.ReadEndDocument();
            return value;
        }
开发者ID:labeuze,项目名称:source,代码行数:15,代码来源:OXmlSimpleFieldElementSerializer.cs

示例10: Deserialize

        // public methods
#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(BitArray));

            BsonType bsonType = bsonReader.GetCurrentBsonType();
            BitArray bitArray;
            switch (bsonType)
            {
                case BsonType.Null:
                    bsonReader.ReadNull();
                    return null;
                case BsonType.Binary:
                    return new BitArray(bsonReader.ReadBytes());
                case BsonType.Document:
                    bsonReader.ReadStartDocument();
                    var length = bsonReader.ReadInt32("Length");
                    var bytes = bsonReader.ReadBytes("Bytes");
                    bsonReader.ReadEndDocument();
                    bitArray = new BitArray(bytes);
                    bitArray.Length = length;
                    return bitArray;
                case BsonType.String:
                    var s = bsonReader.ReadString();
                    bitArray = new BitArray(s.Length);
                    for (int i = 0; i < s.Length; i++)
                    {
                        var c = s[i];
                        switch (c)
                        {
                            case '0':
                                break;
                            case '1':
                                bitArray[i] = true;
                                break;
                            default:
                                throw new FileFormatException("String value is not a valid BitArray.");
                        }
                    }
                    return bitArray;
                default:
                    var message = string.Format("Cannot deserialize Byte[] from BsonType {0}.", bsonType);
                    throw new FileFormatException(message);
            }
        }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:58,代码来源:BitArraySerializer.cs

示例11: ReadCustomObject

        static PSObject ReadCustomObject(BsonReader bsonReader)
        {
            var ps = new PSObject();
            var properties = ps.Properties;

            bsonReader.ReadStartDocument();
            while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
            {
                var name = bsonReader.ReadName();
                var value = ReadObject(bsonReader);
                properties.Add(new PSNoteProperty(name, value), true); //! true is faster
            }
            bsonReader.ReadEndDocument();

            return ps;
        }
开发者ID:nightroman,项目名称:Mdbc,代码行数:16,代码来源:Serializer.cs

示例12: Deserialize

 public override object Deserialize(
  BsonReader bsonReader,
  Type nominalType,
  Type actualType,
  IBsonSerializationOptions options)
 {
     var bsonType = bsonReader.GetCurrentBsonType();
     if (bsonType == BsonType.Null)
     {
         bsonReader.ReadNull();
         return null;
     }
     else if (bsonType == BsonType.Document)
     {
         var dictionary = CreateInstance(nominalType);
         bsonReader.ReadStartDocument();
         var discriminatorConvention = BsonSerializer.LookupDiscriminatorConvention(typeof(object));
         while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
         {
             var key = bsonReader.ReadName();
             //TODO:对键进行字符串留用.Intern.
             if (key.Length < 16)
             {
                 key = String.Intern(key);
             }
             var valueType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
             var valueSerializer = BsonSerializer.LookupSerializer(valueType);
             var value = valueSerializer.Deserialize(bsonReader, typeof(object), valueType, null);
             //dictionary.Add(key, value);
             if (dictionary is IDictionary<string, object>)
             {
                 ((IDictionary<string, object>)dictionary).Add(key, value);
             }
             else if (dictionary is IDictionary)
             {
                 ((IDictionary)dictionary).Add(key, value);
             }
         }
         bsonReader.ReadEndDocument();
         return dictionary;
     }
     else
     {
         var message = string.Format("Can't deserialize a {0} from BsonType {1}", nominalType.FullName, bsonType);
         throw new FileFormatException(message);
     }
 }
开发者ID:abel,项目名称:sinan,代码行数:47,代码来源:VariantBsonSerializer.cs

示例13: Deserialize

 /// <summary>
 /// Deserializes an object from a BsonReader.
 /// </summary>
 /// <param name="bsonReader">The BsonReader.</param>
 /// <param name="nominalType">The nominal type of the object.</param>
 /// <param name="actualType">The actual type of the object.</param>
 /// <param name="options">The serialization options.</param>
 /// <returns>An object.</returns>
 public override object Deserialize(
     BsonReader bsonReader,
     Type nominalType,
     Type actualType, // ignored
     IBsonSerializationOptions options
 ) {
     var bsonType = bsonReader.CurrentBsonType;
     if (bsonType == BsonType.Null) {
         bsonReader.ReadNull();
         return null;
     } else if (bsonType == BsonType.Document) {
         var dictionary = CreateInstance(nominalType);
         bsonReader.ReadStartDocument();
         var discriminatorConvention = BsonDefaultSerializer.LookupDiscriminatorConvention(typeof(object));
         while (bsonReader.ReadBsonType() != BsonType.EndOfDocument) {
             var key = bsonReader.ReadName();
             var valueType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
             var valueSerializer = BsonSerializer.LookupSerializer(valueType);
             var value = valueSerializer.Deserialize(bsonReader, typeof(object), valueType, null);
             dictionary.Add(key, value);
         }
         bsonReader.ReadEndDocument();
         return dictionary;
     } else if (bsonType == BsonType.Array) {
         var dictionary = CreateInstance(nominalType);
         bsonReader.ReadStartArray();
         var discriminatorConvention = BsonDefaultSerializer.LookupDiscriminatorConvention(typeof(object));
         while (bsonReader.ReadBsonType() != BsonType.EndOfDocument) {
             bsonReader.ReadStartArray();
             bsonReader.ReadBsonType();
             var keyType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
             var keySerializer = BsonSerializer.LookupSerializer(keyType);
             var key = keySerializer.Deserialize(bsonReader, typeof(object), keyType, null);
             bsonReader.ReadBsonType();
             var valueType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
             var valueSerializer = BsonSerializer.LookupSerializer(valueType);
             var value = valueSerializer.Deserialize(bsonReader, typeof(object), valueType, null);
             bsonReader.ReadEndArray();
             dictionary.Add(key, value);
         }
         bsonReader.ReadEndArray();
         return dictionary;
     } else {
         var message = string.Format("Can't deserialize a {0} from BsonType {1}.", nominalType.FullName, bsonType);
         throw new FileFormatException(message);
     }
 }
开发者ID:kamiff,项目名称:mongo-csharp-driver,代码行数:55,代码来源:DictionarySerializer.cs

示例14: Deserialize

        public override object Deserialize(
			BsonReader bsonReader,
			Type nominalType,
			IBsonSerializationOptions options
			)
        {
            var nvc = new NameValueCollection();
            bsonReader.ReadStartDocument();
            while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
            {
                var name = bsonReader.ReadName().Replace("__period__", ".");
                var value = bsonReader.ReadString();
                nvc.Add(name, value);
            }
            bsonReader.ReadEndDocument();
            return nvc;
        }
开发者ID:JefClaes,项目名称:elmah-mongodb,代码行数:17,代码来源:NameValueCollectionSerializer.cs

示例15: Deserialize

        public override object Deserialize( BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options )
        {
            BsonType bsonType = bsonReader.CurrentBsonType;

            object result;

            if( bsonType == BsonType.Null )
            {
                bsonReader.ReadNull();
                result = null;
            }
            else
            {
                if( bsonType == BsonType.Document )
                {
                    var dictionary = new DynamicDictionary();

                    bsonReader.ReadStartDocument();

                    IDiscriminatorConvention valueDiscriminatorConvention = BsonSerializer.LookupDiscriminatorConvention( typeof( object ) );

                    while( bsonReader.ReadBsonType() != BsonType.EndOfDocument )
                    {
                        string key = bsonReader.ReadName();
                        Type valueType = valueDiscriminatorConvention.GetActualType( bsonReader, typeof( object ) );
                        IBsonSerializer valueSerializer = BsonSerializer.LookupSerializer( valueType );
                        object value = valueSerializer.Deserialize( bsonReader, typeof( object ), valueType, null );

                        if( key != "_t" )
                        {
                            dictionary.Add( key.Replace( '\x03', '.' ), value );
                        }
                    }
                    bsonReader.ReadEndDocument();
                    result = dictionary;
                }
                else
                {
                    string message = string.Format( "Can't deserialize a {0} from BsonType {1}.", nominalType.FullName, bsonType );
                    throw new BsonException( message );
                }
            }

            return result;
        }
开发者ID:RabidArts,项目名称:TrivialMongoMessageQueue,代码行数:45,代码来源:DynamicDictionarySerializer.cs


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