本文整理汇总了C#中MongoDB.Bson.IO.BsonReader.GetCurrentBsonType方法的典型用法代码示例。如果您正苦于以下问题:C# BsonReader.GetCurrentBsonType方法的具体用法?C# BsonReader.GetCurrentBsonType怎么用?C# BsonReader.GetCurrentBsonType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Bson.IO.BsonReader
的用法示例。
在下文中一共展示了BsonReader.GetCurrentBsonType方法的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(BsonBinaryData));
var bsonType = bsonReader.GetCurrentBsonType();
switch (bsonType)
{
case BsonType.Null:
bsonReader.ReadNull();
return null;
case BsonType.Binary:
byte[] bytes;
BsonBinarySubType subType;
GuidRepresentation guidRepresentation;
bsonReader.ReadBinaryData(out bytes, out subType, out guidRepresentation);
return new BsonBinaryData(bytes, subType, guidRepresentation);
default:
var message = string.Format("Cannot deserialize BsonBinaryData 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, Type actualType, IBsonSerializationOptions options)
{
if (_trace)
pb.Trace.WriteLine("ZStringArraySerializer.Deserialize()");
VerifyTypes(nominalType, actualType, typeof(ZStringArray));
var bsonType = bsonReader.GetCurrentBsonType();
switch (bsonType)
{
case BsonType.Array:
bsonReader.ReadStartArray();
//return new ZString(bsonReader.ReadString());
var array = new List<string>();
bsonType = bsonReader.ReadBsonType();
while (bsonType != BsonType.EndOfDocument)
{
if (bsonType != BsonType.String)
throw new PBException("error ZStringArray cannot contain value of type {0}", bsonType);
var value = bsonReader.ReadString();
array.Add(value);
bsonType = bsonReader.ReadBsonType();
}
bsonReader.ReadEndArray();
return new ZStringArray(array.ToArray());
default:
throw new PBException("error cannot deserialize ZStringArray from BsonType {0}.", bsonType);
}
}
示例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);
}
}
示例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, // 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);
}
}
示例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="options">The serialization options.</param>
/// <returns>An object.</returns>
public object Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options)
{
VerifyNominalType(nominalType);
if (bsonReader.GetCurrentBsonType() == Bson.BsonType.Null)
{
bsonReader.ReadNull();
return null;
}
else
{
var discriminatorConvention = BsonDefaultSerializer.LookupDiscriminatorConvention(nominalType);
var actualType = discriminatorConvention.GetActualType(bsonReader, nominalType);
if (actualType != nominalType)
{
var serializer = BsonSerializer.LookupSerializer(actualType);
if (serializer != this)
{
// in rare cases a concrete actualType might have a more specialized serializer
return serializer.Deserialize(bsonReader, nominalType, actualType, options);
}
}
return Deserialize(bsonReader, nominalType, actualType, options);
}
}
示例8: 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
示例9: 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(ObjectId));
BsonType bsonType = bsonReader.GetCurrentBsonType();
switch (bsonType)
{
case BsonType.ObjectId:
int timestamp;
int machine;
short pid;
int increment;
bsonReader.ReadObjectId(out timestamp, out machine, out pid, out increment);
return new ObjectId(timestamp, machine, pid, increment);
case BsonType.String:
return ObjectId.Parse(bsonReader.ReadString());
default:
var message = string.Format("Cannot deserialize ObjectId from BsonType {0}.", bsonType);
throw new FileFormatException(message);
}
}
示例10: 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);
}
}
示例11: 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(BsonArray));
var bsonType = bsonReader.GetCurrentBsonType();
switch (bsonType)
{
case BsonType.Array:
bsonReader.ReadStartArray();
var array = new BsonArray();
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
{
var value = (BsonValue)BsonValueSerializer.Instance.Deserialize(bsonReader, typeof(BsonValue), null);
array.Add(value);
}
bsonReader.ReadEndArray();
return array;
default:
var message = string.Format("Cannot deserialize BsonArray from BsonType {0}.", bsonType);
throw new FileFormatException(message);
}
}
示例12: 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);
}
}
示例13: Deserialize
public override object Deserialize(
BsonReader bsonReader,
Type nominalType,
IBsonSerializationOptions options
)
{
var bsonType = bsonReader.GetCurrentBsonType();
if (bsonType == BsonType.Null)
{
bsonReader.ReadNull();
return null;
}
var nvc = new NameValueCollection();
bsonReader.ReadStartArray();
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
{
bsonReader.ReadStartArray();
var key = (string)StringSerializer.Instance.Deserialize(bsonReader, typeof(string), options);
var val = (string)StringSerializer.Instance.Deserialize(bsonReader, typeof(string), options);
bsonReader.ReadEndArray();
nvc.Add(key, val);
}
bsonReader.ReadEndArray();
return nvc;
}
示例14: 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)
{
var bsonType = bsonReader.GetCurrentBsonType();
if (bsonType == BsonType.Null)
{
bsonReader.ReadNull();
return null;
}
else if (bsonType == BsonType.Array)
{
bsonReader.ReadStartArray();
var list = new ArrayList();
var discriminatorConvention = BsonDefaultSerializer.LookupDiscriminatorConvention(typeof(object));
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
{
var elementType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
var serializer = BsonSerializer.LookupSerializer(elementType);
var element = serializer.Deserialize(bsonReader, typeof(object), elementType, null);
list.Add(element);
}
bsonReader.ReadEndArray();
return list;
}
else
{
var message = string.Format("Can't deserialize a {0} from BsonType {1}.", nominalType.FullName, bsonType);
throw new FileFormatException(message);
}
}
示例15: 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);
}
}