本文整理汇总了C#中MongoDB.Bson.IO.BsonReader.SkipName方法的典型用法代码示例。如果您正苦于以下问题:C# BsonReader.SkipName方法的具体用法?C# BsonReader.SkipName怎么用?C# BsonReader.SkipName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Bson.IO.BsonReader
的用法示例。
在下文中一共展示了BsonReader.SkipName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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.Array) {
bsonReader.ReadStartArray();
var list = new ArrayList();
var discriminatorConvention = BsonDefaultSerializer.LookupDiscriminatorConvention(typeof(object));
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument) {
bsonReader.SkipName();
var elementType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
var serializer = BsonSerializer.LookupSerializer(elementType);
var element = serializer.Deserialize(bsonReader, typeof(object), elementType);
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);
}
}
示例2: Deserialize
public override object Deserialize(
BsonReader bsonReader,
Type nominalType,
IBsonSerializationOptions options
)
{
var bsonType = bsonReader.CurrentBsonType;
if (bsonType == BsonType.Null) {
bsonReader.ReadNull();
return null;
} else if (bsonType == BsonType.Document) {
var dictionary = CreateInstance(nominalType);
bsonReader.ReadStartDocument();
var discriminatorConvention = BsonDefaultSerializer.LookupDiscriminatorConvention(typeof(object));
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument) {
var key = bsonReader.ReadName();
var valueType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
var valueSerializer = BsonSerializer.LookupSerializer(valueType);
var value = valueSerializer.Deserialize(bsonReader, typeof(object), valueType, null);
dictionary.Add(key, value);
}
bsonReader.ReadEndDocument();
return dictionary;
} else if (bsonType == BsonType.Array) {
var dictionary = CreateInstance(nominalType);
bsonReader.ReadStartArray();
var discriminatorConvention = BsonDefaultSerializer.LookupDiscriminatorConvention(typeof(object));
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument) {
bsonReader.SkipName();
bsonReader.ReadStartArray();
bsonReader.ReadBsonType();
bsonReader.SkipName();
var keyType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
var keySerializer = BsonSerializer.LookupSerializer(keyType);
var key = keySerializer.Deserialize(bsonReader, typeof(object), keyType, null);
bsonReader.ReadBsonType();
bsonReader.SkipName();
var valueType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
var valueSerializer = BsonSerializer.LookupSerializer(valueType);
var value = valueSerializer.Deserialize(bsonReader, typeof(object), valueType, null);
bsonReader.ReadEndArray();
dictionary.Add(key, 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);
}
}