本文整理汇总了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;
}
示例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);
}
}
示例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);
}
}
示例4: Deserialize
public override object Deserialize(
BsonReader bsonReader,
Type nominalType
)
{
return bsonReader.ReadBoolean();
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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());
}
示例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;
}
示例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);
}
}
示例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");
}
示例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}");
//.........这里部分代码省略.........
示例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());
}
示例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);
}
}