本文整理汇总了C#中BsonReader.ReadEndArray方法的典型用法代码示例。如果您正苦于以下问题:C# BsonReader.ReadEndArray方法的具体用法?C# BsonReader.ReadEndArray怎么用?C# BsonReader.ReadEndArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonReader
的用法示例。
在下文中一共展示了BsonReader.ReadEndArray方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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(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 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)
{
var arraySerializationOptions = EnsureSerializationOptions<ArraySerializationOptions>(options);
var itemSerializationOptions = arraySerializationOptions.ItemSerializationOptions;
var bsonType = bsonReader.GetCurrentBsonType();
switch (bsonType)
{
case BsonType.Null:
bsonReader.ReadNull();
return null;
case BsonType.Array:
var instance = CreateInstance(actualType);
var itemDiscriminatorConvention = BsonSerializer.LookupDiscriminatorConvention(typeof(object));
Type lastItemType = null;
IBsonSerializer lastItemSerializer = null;
bsonReader.ReadStartArray();
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
{
var itemType = itemDiscriminatorConvention.GetActualType(bsonReader, typeof(object));
IBsonSerializer itemSerializer;
if (itemType == lastItemType)
{
itemSerializer = lastItemSerializer;
}
else
{
itemSerializer = BsonSerializer.LookupSerializer(itemType);
lastItemType = itemType;
lastItemSerializer = itemSerializer;
}
var item = itemSerializer.Deserialize(bsonReader, typeof(object), itemType, itemSerializationOptions);
AddItem(instance, item);
}
bsonReader.ReadEndArray();
return FinalizeResult(instance, actualType);
case BsonType.Document:
bsonReader.ReadStartDocument();
bsonReader.ReadString("_t"); // skip over discriminator
bsonReader.ReadName("_v");
var value = Deserialize(bsonReader, actualType, actualType, options);
bsonReader.ReadEndDocument();
return value;
default:
var message = string.Format("Can't deserialize a {0} from BsonType {1}.", nominalType.FullName, 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)
{
var dictionarySerializationOptions = EnsureSerializationOptions(options);
var dictionaryRepresentation = dictionarySerializationOptions.Representation;
var keyValuePairSerializationOptions = dictionarySerializationOptions.KeyValuePairSerializationOptions;
var bsonType = bsonReader.GetCurrentBsonType();
if (bsonType == BsonType.Null)
{
bsonReader.ReadNull();
return null;
}
else if (bsonType == BsonType.Document)
{
if (nominalType == typeof(object))
{
bsonReader.ReadStartDocument();
bsonReader.ReadString("_t"); // skip over discriminator
bsonReader.ReadName("_v");
var value = Deserialize(bsonReader, actualType, options); // recursive call replacing nominalType with actualType
bsonReader.ReadEndDocument();
return value;
}
var dictionary = CreateInstance(actualType);
var valueDiscriminatorConvention = BsonSerializer.LookupDiscriminatorConvention(typeof(object));
bsonReader.ReadStartDocument();
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
{
var key = bsonReader.ReadName();
var valueType = valueDiscriminatorConvention.GetActualType(bsonReader, typeof(object));
var valueSerializer = BsonSerializer.LookupSerializer(valueType);
var value = valueSerializer.Deserialize(bsonReader, typeof(object), valueType, keyValuePairSerializationOptions.ValueSerializationOptions);
dictionary.Add(key, value);
}
bsonReader.ReadEndDocument();
return dictionary;
}
else if (bsonType == BsonType.Array)
{
var dictionary = CreateInstance(actualType);
bsonReader.ReadStartArray();
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
{
var keyValuePair = (KeyValuePair<object, object>)_keyValuePairSerializer.Deserialize(
bsonReader,
typeof(KeyValuePair<object, object>),
keyValuePairSerializationOptions);
dictionary.Add(keyValuePair.Key, keyValuePair.Value);
}
bsonReader.ReadEndArray();
return dictionary;
}
else
{
var message = string.Format("Can't deserialize a {0} from BsonType {1}.", nominalType.FullName, bsonType);
throw new FileFormatException(message);
}
}
示例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)
{
var arraySerializationOptions = EnsureSerializationOptions<ArraySerializationOptions>(options);
var itemSerializationOptions = arraySerializationOptions.ItemSerializationOptions;
var bsonType = bsonReader.GetCurrentBsonType();
switch (bsonType)
{
case BsonType.Null:
bsonReader.ReadNull();
return null;
case BsonType.Array:
bsonReader.ReadStartArray();
var stack = new Stack();
var discriminatorConvention = BsonSerializer.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, itemSerializationOptions);
stack.Push(element);
}
bsonReader.ReadEndArray();
return stack;
case BsonType.Document:
bsonReader.ReadStartDocument();
bsonReader.ReadString("_t"); // skip over discriminator
bsonReader.ReadName("_v");
var value = Deserialize(bsonReader, actualType, actualType, options);
bsonReader.ReadEndDocument();
return value;
default:
var message = string.Format("Can't deserialize a {0} from BsonType {1}.", nominalType.FullName, bsonType);
throw new FileFormatException(message);
}
}