本文整理汇总了C#中MongoDB.Bson.IO.BsonReader.ReadInt32方法的典型用法代码示例。如果您正苦于以下问题:C# BsonReader.ReadInt32方法的具体用法?C# BsonReader.ReadInt32怎么用?C# BsonReader.ReadInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Bson.IO.BsonReader
的用法示例。
在下文中一共展示了BsonReader.ReadInt32方法的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)
{
VerifyTypes(nominalType, actualType, typeof(double));
var representationSerializationOptions = EnsureSerializationOptions<RepresentationSerializationOptions>(options);
var bsonType = bsonReader.GetCurrentBsonType();
switch (bsonType)
{
case BsonType.Double:
return bsonReader.ReadDouble();
case BsonType.Int32:
return representationSerializationOptions.ToDouble(bsonReader.ReadInt32());
case BsonType.Int64:
return representationSerializationOptions.ToDouble(bsonReader.ReadInt64());
case BsonType.String:
return XmlConvert.ToDouble(bsonReader.ReadString());
default:
var message = string.Format("Cannot deserialize Double from BsonType {0}.", bsonType);
throw new FileFormatException(message);
}
}
示例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(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);
}
}
示例3: TestArrayTwoElements
public void TestArrayTwoElements() {
var json = "[1, 2]";
using (bsonReader = BsonReader.Create(json)) {
Assert.AreEqual(BsonType.Array, bsonReader.ReadBsonType());
bsonReader.ReadStartArray();
Assert.AreEqual(BsonType.Int32, bsonReader.ReadBsonType());
Assert.AreEqual(1, bsonReader.ReadInt32());
Assert.AreEqual(BsonType.Int32, bsonReader.ReadBsonType());
Assert.AreEqual(2, bsonReader.ReadInt32());
Assert.AreEqual(BsonType.EndOfDocument, bsonReader.ReadBsonType());
bsonReader.ReadEndArray();
Assert.AreEqual(BsonReaderState.Done, bsonReader.State);
}
Assert.AreEqual(json, BsonSerializer.Deserialize<BsonArray>(new StringReader(json)).ToJson());
}
示例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(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);
}
}
示例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(decimal));
var representationSerializationOptions = EnsureSerializationOptions<RepresentationSerializationOptions>(options);
var bsonType = bsonReader.GetCurrentBsonType();
switch (bsonType)
{
case BsonType.Array:
var array = (BsonArray)BsonArraySerializer.Instance.Deserialize(bsonReader, typeof(BsonArray), null);
var bits = new int[4];
bits[0] = array[0].AsInt32;
bits[1] = array[1].AsInt32;
bits[2] = array[2].AsInt32;
bits[3] = array[3].AsInt32;
return new decimal(bits);
case BsonType.Double:
return representationSerializationOptions.ToDecimal(bsonReader.ReadDouble());
case BsonType.Int32:
return representationSerializationOptions.ToDecimal(bsonReader.ReadInt32());
case BsonType.Int64:
return representationSerializationOptions.ToDecimal(bsonReader.ReadInt64());
case BsonType.String:
return XmlConvert.ToDecimal(bsonReader.ReadString());
default:
var message = string.Format("Cannot deserialize Decimal from BsonType {0}.", bsonType);
throw new FileFormatException(message);
}
}
示例6: ReadPageSize
private static OXmlPageSize ReadPageSize(BsonReader bsonReader)
{
bsonReader.ReadStartDocument();
OXmlPageSize value = new OXmlPageSize();
while (true)
{
BsonType bsonType = bsonReader.ReadBsonType();
if (bsonType == BsonType.EndOfDocument)
break;
string name = bsonReader.ReadName();
switch (name.ToLower())
{
case "width":
if (bsonType == BsonType.Null)
break;
if (bsonType != BsonType.Int32)
throw new PBException($"wrong PageSize width value {bsonType}");
value.Width = bsonReader.ReadInt32();
break;
case "height":
if (bsonType == BsonType.Null)
break;
if (bsonType != BsonType.Int32)
throw new PBException($"wrong PageSize height value {bsonType}");
value.Height = bsonReader.ReadInt32();
break;
default:
throw new PBException($"unknow PageSize value \"{name}\"");
}
}
bsonReader.ReadEndDocument();
return value;
}
示例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(TimeSpan));
// support RepresentationSerializationOptions for backward compatibility
var representationSerializationOptions = options as RepresentationSerializationOptions;
if (representationSerializationOptions != null)
{
options = new TimeSpanSerializationOptions(representationSerializationOptions.Representation);
}
var timeSpanSerializationOptions = EnsureSerializationOptions<TimeSpanSerializationOptions>(options);
BsonType bsonType = bsonReader.GetCurrentBsonType();
switch (bsonType)
{
case BsonType.Double:
return FromDouble(bsonReader.ReadDouble(), timeSpanSerializationOptions.Units);
case BsonType.Int32:
return FromInt32(bsonReader.ReadInt32(), timeSpanSerializationOptions.Units);
case BsonType.Int64:
return FromInt64(bsonReader.ReadInt64(), timeSpanSerializationOptions.Units);
case BsonType.String:
return TimeSpan.Parse(bsonReader.ReadString()); // not XmlConvert.ToTimeSpan (we're using .NET's format for TimeSpan)
default:
var message = string.Format("Cannot deserialize TimeSpan from BsonType {0}.", bsonType);
throw new FileFormatException(message);
}
}
示例8: Deserialize
public override object Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options)
{
var id = bsonReader.ReadInt32();
if (id == 0)
return null;
return database.IdentityMap.GetOrCreate(id, (i) => database.GetCollection<ContentItem>().FindOne(Query.EQ("_id", i)));
}
示例9: 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();
}
示例10: 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;
}
示例11: Deserialize
public override object Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options)
{
var id = bsonReader.ReadInt32();
if (id == 0)
return ContentRelation.Empty;
return new ContentRelation(id, Get);
}
示例12: Deserialize
static object Deserialize(BsonReader bsonReader)
{
var currentBsonType = bsonReader.GetCurrentBsonType();
switch (currentBsonType)
{
case BsonType.Null:
return null;
case BsonType.Document:
bsonReader.ReadStartDocument();
var hour = bsonReader.ReadInt32("Hour");
var minute = bsonReader.ReadInt32("Minute");
var second = bsonReader.ReadInt32("Second");
bsonReader.ReadEndDocument();
return new TimeOfDay(hour, minute, second);
default:
throw new NotSupportedException(
string.Format("Bson type : {0} is not supported for TimeOfDay type property", currentBsonType));
}
}
示例13: 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);
}
}
示例14: Deserialize
public override object Deserialize(BsonReader bsonReader,
Type nominalType, Type actualType, IBsonSerializationOptions options) {
if (nominalType != typeof(Category) || actualType != typeof(Category)) {
throw new BsonSerializationException("This serializer can only serialize type PingApp.Entity.Category");
}
if (bsonReader.GetCurrentBsonType() != BsonType.Int32) {
throw new FormatException("Category should be serialized to Int32");
}
int id = bsonReader.ReadInt32();
return Category.Get(id);
}
示例15: Deserialize
public override object Deserialize(BsonReader bsonReader,
Type nominalType, Type actualType, IBsonSerializationOptions options) {
if (nominalType != typeof(AppBrief) || actualType != typeof(AppBrief)) {
throw new BsonSerializationException("This serializer can only serialize type PingApp.Entity.AppBrief");
}
if (bsonReader.GetCurrentBsonType() != BsonType.Int32) {
throw new FormatException("AppBrief should be serialized to Int32");
}
int id = bsonReader.ReadInt32();
return new AppBrief() { Id = id };
}