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


C# BsonReader.ReadBoolean方法代码示例

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


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

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

示例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(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:ncipollina,项目名称:mongo-csharp-driver,代码行数:38,代码来源:BsonPrimitiveSerializers.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

 public override object Deserialize(
     BsonReader bsonReader,
     Type nominalType
 )
 {
     return bsonReader.ReadBoolean();
 }
开发者ID:tomthink,项目名称:mongo-csharp-driver,代码行数:7,代码来源:BsonPrimitiveSerializers.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(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

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

            var bsonType = bsonReader.GetCurrentBsonType();
            switch (bsonType)
            {
                case BsonType.Boolean:
                    return (BsonBoolean)bsonReader.ReadBoolean();
                default:
                    var message = string.Format("Cannot deserialize BsonBoolean from BsonType {0}.", bsonType);
                    throw new FileFormatException(message);
            }
        }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:27,代码来源:BsonBooleanSerializer.cs

示例7: _Deserialize

 public OXmlTextElement _Deserialize(BsonReader bsonReader, IBsonSerializationOptions options)
 {
     OXmlTextElement element = new OXmlTextElement();
     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() != "text")
                     throw new PBException($"invalid Type {type} when deserialize OXmlTextElement");
                 break;
             case "text":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong text value {bsonType}");
                 element.Text = bsonReader.ReadString();
                 break;
             case "preservespace":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong PreserveSpace value {bsonType}");
                 element.PreserveSpace = bsonReader.ReadBoolean();
                 break;
             default:
                 throw new PBException($"unknow Text value \"{name}\"");
         }
     }
     return element;
 }
开发者ID:labeuze,项目名称:source,代码行数:38,代码来源:OXmlTextElementSerializer.cs

示例8: 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
 ) {
     var bsonType = bsonReader.CurrentBsonType;
     switch (bsonType) {
         case BsonType.Null:
             bsonReader.ReadNull();
             return BsonNull.Value;
         case BsonType.Document:
             bsonReader.ReadStartDocument();
             var csharpNull = bsonReader.ReadBoolean("$csharpnull");
             bsonReader.ReadEndDocument();
             return csharpNull ? null : BsonNull.Value;
         default:
             var message = string.Format("Cannot deserialize BsonNull from BsonType {0}.", bsonType);
             throw new FileFormatException(message);
     }
 }
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:27,代码来源:BsonValueSerializers.cs

示例9: TestBooleanFalse

 public void TestBooleanFalse()
 {
     var json = "false";
     using (_bsonReader = new JsonReader(json))
     {
         Assert.AreEqual(BsonType.Boolean, _bsonReader.ReadBsonType());
         Assert.AreEqual(false, _bsonReader.ReadBoolean());
         Assert.AreEqual(BsonReaderState.Done, _bsonReader.State);
     }
     Assert.AreEqual(json, BsonSerializer.Deserialize<bool>(json).ToJson());
 }
开发者ID:Bogdan0x400,项目名称:mongo-csharp-driver,代码行数:11,代码来源:JsonReaderTests.cs

示例10: IsCSharpNullRepresentation

        private bool IsCSharpNullRepresentation(BsonReader bsonReader)
        {
            var bookmark = bsonReader.GetBookmark();
            bsonReader.ReadStartDocument();
            var bsonType = bsonReader.ReadBsonType();
            if (bsonType == BsonType.Boolean)
            {
                var name = bsonReader.ReadName();
                if (name == "_csharpnull" || name == "$csharpnull")
                {
                    var value = bsonReader.ReadBoolean();
                    if (value)
                    {
                        bsonType = bsonReader.ReadBsonType();
                        if (bsonType == BsonType.EndOfDocument)
                        {
                            bsonReader.ReadEndDocument();
                            return true;
                        }
                    }
                }
            }

            bsonReader.ReturnToBookmark(bookmark);
            return false;
        }
开发者ID:robinNode,项目名称:mongo-csharp-driver,代码行数:26,代码来源:BsonClassMapSerializer.cs

示例11: Deserialize

 public override object Deserialize(
     BsonReader bsonReader,
     Type nominalType
 ) {
     var bsonType = bsonReader.CurrentBsonType;
     if (bsonType == BsonType.Null) {
         bsonReader.ReadNull();
         return null;
     } else if (bsonType == BsonType.String) {
         return new CultureInfo(bsonReader.ReadString());
     } else if (bsonType == BsonType.Document) {
         bsonReader.ReadStartDocument();
         var name = bsonReader.ReadString("Name");
         var useUserOverride = bsonReader.ReadBoolean("UseUserOverride");
         bsonReader.ReadEndDocument();
         return new CultureInfo(name, useUserOverride);
     } else {
         var message = string.Format("Cannot deserialize CultureInfo from BsonType: {0}", bsonType);
         throw new FileFormatException(message);
     }
 }
开发者ID:kenegozi,项目名称:mongo-csharp-driver,代码行数:21,代码来源:NetPrimitiveSerializers.cs

示例12: Deserialize

 public override object Deserialize(
     BsonReader bsonReader,
     Type nominalType
 )
 {
     var bsonType = bsonReader.CurrentBsonType;
     if (bsonType == BsonType.Null) {
         bsonReader.ReadNull();
         return BsonNull.Value;
     } else if (bsonType == BsonType.Document) {
         bsonReader.ReadStartDocument();
         var csharpNull = bsonReader.ReadBoolean("$csharpnull");
         bsonReader.ReadEndDocument();
         return csharpNull ? null : BsonNull.Value;
     }
     throw new FileFormatException("Invalid representation for BsonNull");
 }
开发者ID:kenegozi,项目名称:mongo-csharp-driver,代码行数:17,代码来源:BsonValueSerializers.cs

示例13: _Deserialize

 public OXmlStyleElement _Deserialize(BsonReader bsonReader, IBsonSerializationOptions options)
 {
     OXmlStyleElement element = new OXmlStyleElement();
     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() != "style")
                     throw new PBException($"invalid Type {type} when deserialize OXmlStyleElement");
                 break;
             case "id":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong Id value {bsonType}");
                 element.Id = bsonReader.ReadString();
                 break;
             case "name":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong Name value {bsonType}");
                 element.Name = bsonReader.ReadString();
                 break;
             case "styletype":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong StyleType value {bsonType}");
                 element.StyleType = bsonReader.ReadString().zParseEnum<StyleValues>(ignoreCase: true);
                 break;
             case "aliases":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong Aliases value {bsonType}");
                 element.Aliases = bsonReader.ReadString();
                 break;
             case "customstyle":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong CustomStyle value {bsonType}");
                 element.CustomStyle = bsonReader.ReadBoolean();
                 break;
             case "defaultstyle":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong DefaultStyle value {bsonType}");
                 element.DefaultStyle = bsonReader.ReadBoolean();
                 break;
             case "locked":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong Locked value {bsonType}");
                 element.Locked = bsonReader.ReadBoolean();
                 break;
             case "semihidden":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong SemiHidden value {bsonType}");
                 element.SemiHidden = bsonReader.ReadBoolean();
                 break;
             case "stylehidden":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong StyleHidden value {bsonType}");
                 element.StyleHidden = bsonReader.ReadBoolean();
                 break;
             case "unhidewhenused":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Boolean)
                     throw new PBException($"wrong UnhideWhenUsed value {bsonType}");
                 element.UnhideWhenUsed = bsonReader.ReadBoolean();
                 break;
             case "uipriority":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.Int32)
                     throw new PBException($"wrong UIPriority value {bsonType}");
                 element.UIPriority = bsonReader.ReadInt32();
                 break;
             case "linkedstyle":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong LinkedStyle value {bsonType}");
//.........这里部分代码省略.........
开发者ID:labeuze,项目名称:source,代码行数:101,代码来源:OXmlStyleElementSerializer.cs

示例14: TestBooleanTrue

 public void TestBooleanTrue() {
     var json = "true";
     using (bsonReader = BsonReader.Create(json)) {
         Assert.AreEqual(BsonType.Boolean, bsonReader.ReadBsonType());
         Assert.AreEqual(true, bsonReader.ReadBoolean());
         Assert.AreEqual(BsonReaderState.Done, bsonReader.State);
     }
     Assert.AreEqual(json, BsonSerializer.Deserialize<bool>(new StringReader(json)).ToJson());
 }
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:9,代码来源:JsonReaderTests.cs

示例15: ReadObject

 //_120509_173140 keep consistent
 static object ReadObject(BsonReader bsonReader)
 {
     switch (bsonReader.GetCurrentBsonType())
     {
         case BsonType.Array: return ReadArray(bsonReader); // replacement
         case BsonType.Binary: var binary = BsonSerializer.Deserialize<BsonValue>(bsonReader); return BsonTypeMapper.MapToDotNetValue(binary) ?? binary; // byte[] or Guid else self
         case BsonType.Boolean: return bsonReader.ReadBoolean();
         case BsonType.DateTime: return BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(bsonReader.ReadDateTime());
         case BsonType.Document: return ReadCustomObject(bsonReader); // replacement
         case BsonType.Double: return bsonReader.ReadDouble();
         case BsonType.Int32: return bsonReader.ReadInt32();
         case BsonType.Int64: return bsonReader.ReadInt64();
         case BsonType.Null: bsonReader.ReadNull(); return null;
         case BsonType.ObjectId: return bsonReader.ReadObjectId();
         case BsonType.String: return bsonReader.ReadString();
         default: return BsonSerializer.Deserialize<BsonValue>(bsonReader);
     }
 }
开发者ID:nightroman,项目名称:Mdbc,代码行数:19,代码来源:Serializer.cs


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