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


C# BsonReader类代码示例

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


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

示例1: Deserialize

        public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
        {
            object value = null;
            if (bsonReader.CurrentBsonType == BsonType.Null)
            {
                bsonReader.ReadNull();
            }
            else
            {
                bsonReader.ReadStartArray();
                var idList = new List<ObjectId>();
                while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
                {
                    var id = (ObjectId)BsonSerializer.Deserialize(bsonReader, typeof(ObjectId));
                    idList.Add(id);
                }
                bsonReader.ReadEndArray();

                if (idList.Count > 0)
                {
                    var cursor = MongoDbProvider.Database.GetCollection(DocumentType, DocumentType.Name)
                        .FindAs(DocumentType, Query.In("_id", BsonArray.Create(idList)));

                    var documents = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(DocumentType));
                    foreach (var document in cursor)
                    {
                        documents.Add(document);
                    }
                    value = documents;
                }
            }
            return value;
        }
开发者ID:virajs,项目名称:MongoDB-Mapping-Attributes,代码行数:33,代码来源:OneToManyBsonSerializer.cs

示例2: IsRelationalAssociation

		private static bool IsRelationalAssociation(BsonReader bsonReader, Type nominalType)
		{
			if (bsonReader.State != BsonReaderState.Value || bsonReader.CurrentBsonType != BsonType.ObjectId)
				return false;

			return IsRelationalType(nominalType);
		}
开发者ID:modulexcite,项目名称:ormongo,代码行数:7,代码来源:DocumentSerializer.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, // ignored
     IBsonSerializationOptions options)
 {
     var bsonType = bsonReader.GetCurrentBsonType();
     switch (bsonType)
     {
         case BsonType.Array: return (BsonValue)BsonArraySerializer.Instance.Deserialize(bsonReader, typeof(BsonArray), options);
         case BsonType.Binary: return (BsonValue)BsonBinaryDataSerializer.Instance.Deserialize(bsonReader, typeof(BsonBinaryData), options);
         case BsonType.Boolean: return (BsonValue)BsonBooleanSerializer.Instance.Deserialize(bsonReader, typeof(BsonBoolean), options);
         case BsonType.DateTime: return (BsonValue)BsonDateTimeSerializer.Instance.Deserialize(bsonReader, typeof(BsonDateTime), options);
         case BsonType.Document: return (BsonValue)BsonDocumentSerializer.Instance.Deserialize(bsonReader, typeof(BsonDocument), options);
         case BsonType.Double: return (BsonValue)BsonDoubleSerializer.Instance.Deserialize(bsonReader, typeof(BsonDouble), options);
         case BsonType.Int32: return (BsonValue)BsonInt32Serializer.Instance.Deserialize(bsonReader, typeof(BsonInt32), options);
         case BsonType.Int64: return (BsonValue)BsonInt64Serializer.Instance.Deserialize(bsonReader, typeof(BsonInt64), options);
         case BsonType.JavaScript: return (BsonValue)BsonJavaScriptSerializer.Instance.Deserialize(bsonReader, typeof(BsonJavaScript), options);
         case BsonType.JavaScriptWithScope: return (BsonValue)BsonJavaScriptWithScopeSerializer.Instance.Deserialize(bsonReader, typeof(BsonJavaScriptWithScope), options);
         case BsonType.MaxKey: return (BsonValue)BsonMaxKeySerializer.Instance.Deserialize(bsonReader, typeof(BsonMaxKey), options);
         case BsonType.MinKey: return (BsonValue)BsonMinKeySerializer.Instance.Deserialize(bsonReader, typeof(BsonMinKey), options);
         case BsonType.Null: return (BsonValue)BsonNullSerializer.Instance.Deserialize(bsonReader, typeof(BsonNull), options);
         case BsonType.ObjectId: return (BsonValue)BsonObjectIdSerializer.Instance.Deserialize(bsonReader, typeof(BsonObjectId), options);
         case BsonType.RegularExpression: return (BsonValue)BsonRegularExpressionSerializer.Instance.Deserialize(bsonReader, typeof(BsonRegularExpression), options);
         case BsonType.String: return (BsonValue)BsonStringSerializer.Instance.Deserialize(bsonReader, typeof(BsonString), options);
         case BsonType.Symbol: return (BsonValue)BsonSymbolSerializer.Instance.Deserialize(bsonReader, typeof(BsonSymbol), options);
         case BsonType.Timestamp: return (BsonValue)BsonTimestampSerializer.Instance.Deserialize(bsonReader, typeof(BsonTimestamp), options);
         case BsonType.Undefined: return (BsonValue)BsonUndefinedSerializer.Instance.Deserialize(bsonReader, typeof(BsonUndefined), options);
         default:
             var message = string.Format("Invalid BsonType {0}.", bsonType);
             throw new BsonInternalException(message);
     }
 }
开发者ID:huoxudong125,项目名称:SequoiaDB.Charp,代码行数:39,代码来源:BsonValueSerializer.cs

示例4: 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:huoxudong125,项目名称:SequoiaDB.Charp,代码行数:36,代码来源:CultureInfoSerializer.cs

示例5: Deserialize

 public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
 {
     int timestamp, machine, increment;
     short pid;
     bsonReader.ReadObjectId(out timestamp, out machine, out pid, out increment);
     return new ObjectId(timestamp, machine, pid, increment).ToString();
 }
开发者ID:ncipollina,项目名称:mongo-csharp-driver,代码行数:7,代码来源:CSharp378Tests.cs

示例6: Deserialize

 public object Deserialize(
     BsonReader bsonReader,
     Type nominalType
 )
 {
     throw new InvalidOperationException("Deserialize not valid for BsonDocumentWrapper");
 }
开发者ID:testn,项目名称:mongo-csharp-driver,代码行数:7,代码来源:BsonDocumentWrapper.cs

示例7: 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(bool));

            var bsonType = bsonReader.GetCurrentBsonType();
            switch (bsonType)
            {
                case BsonType.Boolean:
                    return bsonReader.ReadBoolean();
                case BsonType.Double:
                    return bsonReader.ReadDouble() != 0.0;
                case BsonType.Int32:
                    return bsonReader.ReadInt32() != 0;
                case BsonType.Int64:
                    return bsonReader.ReadInt64() != 0;
                case BsonType.Null:
                    bsonReader.ReadNull();
                    return false;
                case BsonType.String:
                    return XmlConvert.ToBoolean(bsonReader.ReadString().ToLower());
                default:
                    var message = string.Format("Cannot deserialize Boolean from BsonType {0}.", bsonType);
                    throw new FileFormatException(message);
            }
        }
开发者ID:huoxudong125,项目名称:SequoiaDB.Charp,代码行数:38,代码来源:BooleanSerializer.cs

示例8: Deserialize

        public object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
        {
            object value = null;
            var valueType = actualType.GetConceptValueType();
			if (valueType == typeof(Guid)) {
				var guidBytes = new byte[16];
				BsonBinarySubType subType;
				bsonReader.ReadBinaryData (out guidBytes, out subType);
				value = new Guid (guidBytes);
			} else if (valueType == typeof(double))
				value = bsonReader.ReadDouble ();
			else if (valueType == typeof(float))
				value = (float)bsonReader.ReadDouble ();
			else if (valueType == typeof(Int32))
				value = bsonReader.ReadInt32 ();
			else if (valueType == typeof(Int64))
				value = bsonReader.ReadInt64 ();
			else if (valueType == typeof(bool))
				value = bsonReader.ReadBoolean ();
			else if (valueType == typeof(string))
				value = bsonReader.ReadString ();
			else if (valueType == typeof(decimal))
				value = decimal.Parse (bsonReader.ReadString ());
            
            var concept = ConceptFactory.CreateConceptInstance(actualType, value);
            return concept;
        }
开发者ID:jarlef,项目名称:Bifrost,代码行数:27,代码来源:ConceptSerializer.cs

示例9: _Deserialize

 public OXmlParagraphElement _Deserialize(BsonReader bsonReader, IBsonSerializationOptions options)
 {
     OXmlParagraphElement paragraph = new OXmlParagraphElement();
     while (true)
     {
         BsonType bsonType = bsonReader.ReadBsonType();
         if (bsonType == BsonType.EndOfDocument)
             break;
         //if (bsonType != BsonType.String)
         //    throw new PBException("error ZStringArray cannot contain value of type {0}", bsonType);
         //var value = bsonReader.ReadString();
         string name = bsonReader.ReadName();
         switch (name.ToLower())
         {
             case "type":
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong type value {bsonType}");
                 string type = bsonReader.ReadString();
                 if (type.ToLower() != "paragraph")
                     throw new PBException($"invalid Type {type} when deserialize OXmlParagraphElement");
                 break;
             case "style":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong style value {bsonType}");
                 paragraph.Style = bsonReader.ReadString();
                 break;
             default:
                 throw new PBException($"unknow Paragraph value \"{name}\"");
         }
     }
     return paragraph;
 }
开发者ID:labeuze,项目名称:source,代码行数:34,代码来源:OXmlParagraphElementSerializer.cs

示例10: _Deserialize

 public OXmlSimpleFieldElement _Deserialize(BsonReader bsonReader, IBsonSerializationOptions options)
 {
     OXmlSimpleFieldElement element = new OXmlSimpleFieldElement();
     while (true)
     {
         BsonType bsonType = bsonReader.ReadBsonType();
         if (bsonType == BsonType.EndOfDocument)
             break;
         string name = bsonReader.ReadName();
         switch (name.ToLower())
         {
             case "type":
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong type value {bsonType}");
                 string type = bsonReader.ReadString();
                 if (type.ToLower() != "simplefield")
                     throw new PBException($"invalid Type {type} when deserialize OXmlSimpleFieldElement");
                 break;
             case "instruction":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong Instruction value {bsonType}");
                 element.Instruction = bsonReader.ReadString();
                 break;
             default:
                 throw new PBException($"unknow SimpleField value \"{name}\"");
         }
     }
     return element;
 }
开发者ID:labeuze,项目名称:source,代码行数:31,代码来源:OXmlSimpleFieldElementSerializer.cs

示例11: _Deserialize

 public OXmlOpenHeaderElement _Deserialize(BsonReader bsonReader, IBsonSerializationOptions options)
 {
     OXmlOpenHeaderElement element = new OXmlOpenHeaderElement();
     while (true)
     {
         BsonType bsonType = bsonReader.ReadBsonType();
         if (bsonType == BsonType.EndOfDocument)
             break;
         string name = bsonReader.ReadName();
         switch (name.ToLower())
         {
             case "type":
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong type value {bsonType}");
                 string type = bsonReader.ReadString();
                 //"openfooter"
                 if (type.ToLower() != "openheader")
                     throw new PBException($"invalid Type {type} when deserialize OXmlOpenHeader");
                 break;
             case "headertype":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong HeaderType value {bsonType}");
                 element.HeaderType = bsonReader.ReadString().zParseEnum<HeaderFooterValues>();
                 break;
             default:
                 //OpenHeaderFooter
                 throw new PBException($"unknow OpenHeader value \"{name}\"");
         }
     }
     return element;
 }
开发者ID:labeuze,项目名称:source,代码行数:33,代码来源:OXmlOpenHeaderElementSerializer.cs

示例12: InvalidOperationException

 object IBsonSerializable.Deserialize(
     BsonReader bsonReader,
     Type nominalType,
     IBsonSerializationOptions options
 ) {
     throw new InvalidOperationException();
 }
开发者ID:ebix,项目名称:mongo-csharp-driver,代码行数:7,代码来源:BuilderBase.cs

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

示例14: Deserialize

        public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
        {
            if (bsonReader.CurrentBsonType == BsonType.Int32)
                return bsonReader.ReadInt32().ToString();

            throw new InvalidOperationException();
        }
开发者ID:hitesh97,项目名称:fluent-mongo,代码行数:7,代码来源:StringInt32Serializer.cs

示例15: Deserialize

 public override object Deserialize(
     BsonReader bsonReader,
     Type nominalType,
     IBsonSerializationOptions options
 ) {
     return XmlConvert.ToDateTime(bsonReader.ReadString(), XmlDateTimeSerializationMode.RoundtripKind);
 }
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:7,代码来源:BsonDefaultSerializerTests.cs


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