本文整理匯總了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);
}
}